Subtile link error

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2008
Posts: 147
Reputation: GDICommander is an unknown quantity at this point 
Solved Threads: 19
GDICommander's Avatar
GDICommander GDICommander is offline Offline
Junior Poster

Subtile link error

 
0
  #1
Jul 29th, 2009
Hello, everyone! It's been a long time using C++ and I have a link problem.

This is the code...

  1. #include <iostream>
  2. #include "libc++/pcslib.h"
  3.  
  4. int main()
  5. {
  6. std::cout << "About to load the server and all the clients." << std::endl;
  7.  
  8. Pcs serverProcess("server");
  9. Pcs clientProcess("client");
  10.  
  11. serverProcess.Join();
  12. clientProcess.Join();
  13.  
  14. std::cout << "After joining with processes." << std::endl;
  15.  
  16. return 0;
  17. }

The included file pcslib.h is:

  1. #include <unistd.h>
  2. #include <stdio.h>
  3. #include <iostream>
  4. #include <sys/wait.h>
  5. #include <signal.h>
  6. #include <errno.h>
  7.  
  8. class Pcs {
  9. private:
  10. int pcsid;
  11. int status;
  12. public:
  13. Pcs();
  14. Pcs(char *fichier);
  15. void Fork(char *fichier);
  16. int Join();
  17. void Detruit();
  18. };

There's a cpp file, pcsfile.cpp, that implements the public methods. When I'm passing the first block of code to the compiler (g++), I'm having this message and I don't know why. Can you help me?

Undefined first referenced
symbol in file
Pcs::Join() /var/tmp//ccsCx3jl.o
Pcs:: Pcs(char*) /var/tmp//ccsCx3jl.o
ld: fatal: Symbol referencing errors. No output written to loader
collect2: ld returned 1 exit status
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 538
Reputation: Murtan is a jewel in the rough Murtan is a jewel in the rough Murtan is a jewel in the rough Murtan is a jewel in the rough 
Solved Threads: 86
Murtan Murtan is offline Offline
Posting Pro

Re: Subtile link error

 
0
  #2
Jul 29th, 2009
It looks like it compiled, so the symbol was defined enough for the compiler to recognize them.

The link process is where the actual executable is built. The linker needs to match up the symbol that your main calls with the actual implementation.

You should probably add the pcsfile.cpp to the g++ command line so that it will compile and the linker will look there for symbol definitions.

There are other ways to do it, but that looks the easiest based on your description.
Last edited by Murtan; Jul 29th, 2009 at 12:57 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 147
Reputation: GDICommander is an unknown quantity at this point 
Solved Threads: 19
GDICommander's Avatar
GDICommander GDICommander is offline Offline
Junior Poster

Re: Subtile link error

 
0
  #3
Jul 29th, 2009
Thank you for your help. It worked when I added pcslib.cpp with the other file on the command line with g++.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC