943,779 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 263
  • C++ RSS
Jul 29th, 2009
0

Subtile link error

Expand Post »
Hello, everyone! It's been a long time using C++ and I have a link problem.

This is the code...

C++ Syntax (Toggle Plain Text)
  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:

C++ Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 72
Solved Threads: 26
Posting Whiz in Training
GDICommander is offline Offline
209 posts
since Jun 2008
Jul 29th, 2009
0

Re: Subtile link error

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.
Reputation Points: 344
Solved Threads: 116
Practically a Master Poster
Murtan is offline Offline
670 posts
since May 2008
Jul 29th, 2009
0

Re: Subtile link error

Thank you for your help. It worked when I added pcslib.cpp with the other file on the command line with g++.
Reputation Points: 72
Solved Threads: 26
Posting Whiz in Training
GDICommander is offline Offline
209 posts
since Jun 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Class Fraction...Need a code
Next Thread in C++ Forum Timeline: Question about graphics and to check a file location





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC