944,147 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 14382
  • C++ RSS
Nov 15th, 2004
0

undefined reference errors when using C++ Sockets Library

Expand Post »
I've just downloaded the C++ sockets library from www.alhem.net/Sockets, but I can't get my programs to link -- I get a lot of "undefined reference"s.... I'm using g++ version 3.3.3. on Fedora Core 2 (kernel version 2.6.5-1.358).
I can get the programs to compile (using the -c flag to g++), but any attempt to link results in the error below. My program is a verbatim copy from the tutorial on the site.
It appears that (some of) the functions for the SocketHandler and TcpSocket classes are not implemented, but I've checked, and they're there!
I'll really appreciate any help anyone can give.

Here's the compiler command I use:

g++ -L/usr/local/lib -I/usr/local/include/Sockets -o sock_test sock_test.cpp

If I use the -c flag to that command, I get no errors, meaning that I can compile, but the linker can't find the functions it's complaining about, right? I wonder if I missed something while downloading?

Please help!!

MT

C++ Syntax (Toggle Plain Text)
  1. /*************************************
  2.  ***** Here's the code *************
  3.  *************************************/
  4. #include <TcpSocket.h>
  5. #include <SocketHandler.h>
  6.  
  7. class DisplaySocket : public TcpSocket {
  8. public:
  9. DisplaySocket(SocketHandler&);
  10. void OnRead();
  11. };
  12.  
  13. DisplaySocket::DisplaySocket(SocketHandler& h) : TcpSocket(h) {}
  14.  
  15. #define RSIZE 1024
  16.  
  17. void DisplaySocket::OnRead() {
  18.  
  19. TcpSocket::OnRead();
  20. size_t n = ibuf.GetLength();
  21. if (n > 0) {
  22. char tmp[RSIZE];
  23.  
  24. n = (n > RSIZE) ? RSIZE : n;
  25. ibuf.Read(tmp, n);
  26. printf("Read %d bytes:\n", n);
  27. for (size_t i = 0; i < n; i++) {
  28. printf("%c", isprint(tmp[i]) ? tmp[i] : '.');
  29. }
  30. printf ("\n");
  31. }
  32. }
  33.  
  34. int main() {
  35. SocketHandler h;
  36. DisplaySocket *p = new DisplaySocket(h);
  37.  
  38. p->SetDeleteByHandler();
  39. p->Open("localhost", 9002);
  40. h.Add(p);
  41. h.Select(1, 0);
  42. while (h.GetCount()) {
  43. h.Select(1, 0);
  44. }
  45. }

/*************************************
***** And here's the error output ***
*************************************/

/tmp/ccbnbrB1.o(.text+0x10): In function `DisplaySocket::DisplaySocket[not-in-charge](SocketHandler&)':
: undefined reference to `TcpSocket::TcpSocket[not-in-charge](SocketHandler&)'
/tmp/ccbnbrB1.o(.text+0x32): In function `DisplaySocket::DisplaySocket[in-charge](SocketHandler&)':
: undefined reference to `TcpSocket::TcpSocket[not-in-charge](SocketHandler&)'
/tmp/ccbnbrB1.o(.text+0x54): In function `DisplaySocket::OnRead()':
: undefined reference to `TcpSocket::OnRead()'
/tmp/ccbnbrB1.o(.text+0xb7): In function `DisplaySocket::OnRead()':
: undefined reference to `CircularBuffer::Read(char*, unsigned)'
/tmp/ccbnbrB1.o(.text+0x17b): In function `main':
: undefined reference to `SocketHandler::SocketHandler[in-charge](StdLog*)'
/tmp/ccbnbrB1.o(.text+0x20e): In function `main':
: undefined reference to `Socket::SetDeleteByHandler(bool)'
/tmp/ccbnbrB1.o(.text+0x25b): In function `main':
: undefined reference to `TcpSocket::Open(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned short)'
/tmp/ccbnbrB1.o(.text+0x2e7): In function `main':
: undefined reference to `SocketHandler::Add(Socket*)'
/tmp/ccbnbrB1.o(.text+0x2fd): In function `main':
: undefined reference to `SocketHandler::Select(long, long)'
/tmp/ccbnbrB1.o(.text+0x30f): In function `main':
: undefined reference to `SocketHandler::GetCount()'
/tmp/ccbnbrB1.o(.text+0x32b): In function `main':
: undefined reference to `SocketHandler::Select(long, long)'
/tmp/ccbnbrB1.o(.text+0x34b): In function `main':
: undefined reference to `SocketHandler::~SocketHandler [in-charge]()'
/tmp/ccbnbrB1.o(.text+0x371): In function `main':
: undefined reference to `SocketHandler::~SocketHandler [in-charge]()'
/tmp/ccbnbrB1.o(.gnu.linkonce.r._ZTV13DisplaySocket+0x10): undefined reference to `Socket::Init()'
/tmp/ccbnbrB1.o(.gnu.linkonce.r._ZTV13DisplaySocket+0x14): undefined reference to `Socket::Close()'
/tmp/ccbnbrB1.o(.gnu.linkonce.r._ZTV13DisplaySocket+0x1c): undefined reference to `TcpSocket::OnWrite()'
/tmp/ccbnbrB1.o(.gnu.linkonce.r._ZTV13DisplaySocket+0x20): undefined reference to `Socket::OnException()'
/tmp/ccbnbrB1.o(.gnu.linkonce.r._ZTV13DisplaySocket+0x24): undefined reference to `Socket::OnDelete()'
/tmp/ccbnbrB1.o(.gnu.linkonce.r._ZTV13DisplaySocket+0x28): undefined reference to `Socket::OnConnect()'
/tmp/ccbnbrB1.o(.gnu.linkonce.r._ZTV13DisplaySocket+0x2c): undefined reference to `Socket::OnAccept()'
/tmp/ccbnbrB1.o(.gnu.linkonce.r._ZTV13DisplaySocket+0x30): undefined reference to `TcpSocket::OnLine(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/tmp/ccbnbrB1.o(.gnu.linkonce.r._ZTV13DisplaySocket+0x34): undefined reference to `Socket::OnSSLInitDone()'
/tmp/ccbnbrB1.o(.gnu.linkonce.r._ZTV13DisplaySocket+0x38): undefined reference to `Socket::OnConnectFailed()'
/tmp/ccbnbrB1.o(.gnu.linkonce.r._ZTV13DisplaySocket+0x3c): undefined reference to `Socket::CheckConnect()'
/tmp/ccbnbrB1.o(.gnu.linkonce.r._ZTV13DisplaySocket+0x40): undefined reference to `TcpSocket::ReadLine()'
/tmp/ccbnbrB1.o(.gnu.linkonce.r._ZTV13DisplaySocket+0x44): undefined reference to `Socket::SSLCheckConnect()'
/tmp/ccbnbrB1.o(.gnu.linkonce.r._ZTV13DisplaySocket+0x4c): undefined reference to `Socket::GetPort()'
/tmp/ccbnbrB1.o(.gnu.linkonce.r._ZTV13DisplaySocket+0x50): undefined reference to `TcpSocket::SendBuf(char const*, unsigned)'
/tmp/ccbnbrB1.o(.gnu.linkonce.t._ZN13DisplaySocketD1Ev+0x16): In function `DisplaySocket::~DisplaySocket [in-charge]()':
: undefined reference to `TcpSocket::~TcpSocket [not-in-charge]()'
/tmp/ccbnbrB1.o(.gnu.linkonce.t._ZN13DisplaySocketD0Ev+0x16): In function `DisplaySocket::~DisplaySocket [in-charge deleting]()':
: undefined reference to `TcpSocket::~TcpSocket [not-in-charge]()'
/tmp/ccbnbrB1.o(.gnu.linkonce.r._ZTI13DisplaySocket+0x8): undefined reference to `typeinfo for TcpSocket'
collect2: ld returned 1 exit status
Last edited by alc6379; Nov 16th, 2004 at 2:52 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
xplst is offline Offline
3 posts
since Nov 2004
Nov 15th, 2004
0

Re: undefined reference errors when using C++ Sockets Library

Try this:
C++ Syntax (Toggle Plain Text)
  1. g++ -o sock_test sock_test.cpp -L/usr/local/lib -I/usr/local/include/Sockets
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Nov 15th, 2004
0

Re: undefined reference errors when using C++ Sockets Library

Quote originally posted by Narue ...
Try this:
C++ Syntax (Toggle Plain Text)
  1. g++ -o sock_test sock_test.cpp -L/usr/local/lib -I/usr/local/include/Sockets
Thanks, Narue. Unfortunately, I still get exactly the same error when I try your suggestion.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
xplst is offline Offline
3 posts
since Nov 2004
Nov 16th, 2004
0

Re: undefined reference errors when using C++ Sockets Library

>I still get exactly the same error when I try your suggestion.
It was worth a shot. Have you tried linking directly with the library (using the -l<lib> switch)?
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Nov 16th, 2004
0

Re: undefined reference errors when using C++ Sockets Library

Are you sure the library is built for your compiler?
You might have to build it from source first if it was compiled against another compiler (version).
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Nov 16th, 2004
0

Re: undefined reference errors when using C++ Sockets Library

Thanks again. Yes, you're right. I eventually had to link directly against my library, and also the pthread library:

... -lSockets -lpthread

Problem now sorted.

Cheers.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
xplst is offline Offline
3 posts
since Nov 2004
Nov 29th, 2004
-1

Re: undefined reference errors when using C++ Sockets Library

I'm having similar issues, but including the lib explicitly doesn't fix it. I'm using Sockets 1.7.1 with the following g++ line:

C++ Syntax (Toggle Plain Text)
  1. g++ `Sockets-config` -o udpserver -I/usr/local/include/Sockets \
  2. -L/usr/local/lib/ -lSockets UdpTestSocket.cpp udpserver.cpp

Of course Sockets-config returns:
C++ Syntax (Toggle Plain Text)
  1. -D_VERSION='"1.7.1"' -DLINUX -DHAVE_OPENSSL
I took udpserver.cpp from the tutorial on the C++ Sockets homepage and modified it just a little. Here's what I'm compiling this:

C++ Syntax (Toggle Plain Text)
  1. #include <StdoutLog.h>
  2. #include <SocketHandler.h>
  3.  
  4. #include "UdpTestSocket.h"
  5.  
  6.  
  7. int main(int argc,char *argv[])
  8. {
  9. SocketHandler h;
  10. StdoutLog log;
  11. h.RegStdLog(&log);
  12. UdpTestSocket s(h);
  13. port_t port = 5353;
  14.  
  15. if (s.Bind(port, 10) == -1)
  16. {
  17. printf("Exiting...\n");
  18. exit(-1);
  19. }
  20. else
  21. {
  22. printf("Ready to receive on port %d\n",port);
  23. }
  24. s.AddMulticastMembership("224.0.0.251");
  25. s.SetMulticastTTL(255);
  26. h.Add(&s);
  27. h.Select(1,0);
  28. while (h.GetCount())
  29. {
  30. h.Select(1,0);
  31. }
  32.  
  33. }

I'm compiling on GNU/Linux using GCC 3.3.4. I compiled this same code on my Powerbook running OS X (10.3.6) using GCC 3.3 by Apple. I had similar problems under OS X, for some reason I had to run ranlib on the library again and it worked fine. Also, I can compile the same on the Linux box to object files, it just doesn't link. This is obvious from the error ouput below.

The exact output is below.

Thanks

bash-2.05b$ g++ `Sockets-config` -o udpserver -I/usr/local/include/Sockets -L/usr/local/lib/ -lSockets UdpTestSocket.cpp udpserver.cpp
/tmp/ccVwaqcS.o(.text+0x1c): In function `UdpTestSocket::UdpTestSocket(SocketHandler&)':
: undefined reference to `UdpSocket::UdpSocket(SocketHandler&, unsigned int)'
/tmp/ccVwaqcS.o(.text+0x48): In function `UdpTestSocket::UdpTestSocket(SocketHandler&)':
: undefined reference to `UdpSocket::UdpSocket(SocketHandler&, unsigned int)'
/tmp/ccVwaqcS.o(.text+0xc2): In function `UdpTestSocket::OnRawData(char const*,unsigned int, sockaddr*, unsigned int)':
: undefined reference to `Socket::l2ip(unsigned long, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'
/tmp/ccVwaqcS.o(.text+0x1f4): In function `UdpTestSocket::OnRawData(char const*, unsigned int, sockaddr*, unsigned int)':
: undefined reference to `Socket::l2ip(in6_addr const&, std::basic_string<char,std::char_traits<char>, std::allocator<char> >&, bool)'
/tmp/ccVwaqcS.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x10): undefined reference to `Socket::Init()'
/tmp/ccVwaqcS.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x14): undefined reference to `Socket::Close()'
/tmp/ccVwaqcS.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x18): undefined reference to `UdpSocket::OnRead()'
/tmp/ccVwaqcS.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x1c): undefined reference to `Socket::OnWrite()'
/tmp/ccVwaqcS.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x20): undefined reference to `Socket::OnException()'
/tmp/ccVwaqcS.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x24): undefined reference to `Socket::OnDelete()'
/tmp/ccVwaqcS.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x28): undefined reference to `Socket::OnConnect()'
/tmp/ccVwaqcS.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x2c): undefined reference to `Socket::OnAccept()'
/tmp/ccVwaqcS.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x30): undefined reference to `Socket::OnLine(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/tmp/ccVwaqcS.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x34): undefined reference to `Socket::OnSSLInitDone()'
/tmp/ccVwaqcS.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x38): undefined reference to `Socket::OnConnectFailed()'
/tmp/ccVwaqcS.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x3c): undefined reference to `Socket::CheckConnect()'
/tmp/ccVwaqcS.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x40): undefined reference to `Socket::ReadLine()'
/tmp/ccVwaqcS.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x44): undefined reference to `Socket:SLCheckConnect()'
/tmp/ccVwaqcS.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x4c): undefined reference to `Socket::GetPort()'
/tmp/ccVwaqcS.o(.gnu.linkonce.t._ZN13UdpTestSocketD1Ev+0x16): In function `UdpTestSocket::~UdpTestSocket()':
: undefined reference to `UdpSocket::~UdpSocket()'
/tmp/ccVwaqcS.o(.gnu.linkonce.t._ZN13UdpTestSocketD0Ev+0x16): In function `UdpTestSocket::~UdpTestSocket()':
: undefined reference to `UdpSocket::~UdpSocket()'
/tmp/ccVwaqcS.o(.gnu.linkonce.r._ZTI13UdpTestSocket+0x8): undefined reference to `typeinfo for UdpSocket'
/tmp/ccpbIqWq.o(.text+0x26): In function `main':
: undefined reference to `SocketHandler:ocketHandler(StdLog*)'
/tmp/ccpbIqWq.o(.text+0x4c): In function `main':
: undefined reference to `SocketHandler::RegStdLog(StdLog*)'
/tmp/ccpbIqWq.o(.text+0x8d): In function `main':
: undefined reference to `UdpSocket::Bind(unsigned short&, int)'
/tmp/ccpbIqWq.o(.text+0x153): In function `main':
: undefined reference to `UdpSocket::AddMulticastMembership(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
/tmp/ccpbIqWq.o(.text+0x22e): In function `main':
: undefined reference to `UdpSocket:etMulticastTTL(int)'
/tmp/ccpbIqWq.o(.text+0x246): In function `main':
: undefined reference to `SocketHandler::Add(Socket*)'
/tmp/ccpbIqWq.o(.text+0x264): In function `main':
: undefined reference to `SocketHandler:elect(long, long)'
/tmp/ccpbIqWq.o(.text+0x272): In function `main':
: undefined reference to `SocketHandler::GetCount()'
/tmp/ccpbIqWq.o(.text+0x296): In function `main':
: undefined reference to `SocketHandler:elect(long, long)'
/tmp/ccpbIqWq.o(.text+0x2e4): In function `main':
: undefined reference to `SocketHandler::~SocketHandler()'
/tmp/ccpbIqWq.o(.text+0x306): In function `main':
: undefined reference to `SocketHandler::~SocketHandler()'
/tmp/ccpbIqWq.o(.gnu.linkonce.t._ZN9StdoutLogC1Ev+0x16): In function `StdoutLog:tdoutLog()':
: undefined reference to `vtable for StdoutLog'
collect2: ld returned 1 exit status
bash-2.05b$ g++ `Sockets-config` -o udpserver -I/usr/local/include/Sockets -L/usr/local/lib/ -lSockets UdpTestSocket.cpp udpserver.cpp
/tmp/ccl6Rgot.o(.text+0x1c): In function `UdpTestSocket::UdpTestSocket(SocketHandler&)':
: undefined reference to `UdpSocket::UdpSocket(SocketHandler&, unsigned int)'
/tmp/ccl6Rgot.o(.text+0x48): In function `UdpTestSocket::UdpTestSocket(SocketHandler&)':
: undefined reference to `UdpSocket::UdpSocket(SocketHandler&, unsigned int)'
/tmp/ccl6Rgot.o(.text+0xc2): In function `UdpTestSocket::OnRawData(char const*,unsigned int, sockaddr*, unsigned int)':
: undefined reference to `Socket::l2ip(unsigned long, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'
/tmp/ccl6Rgot.o(.text+0x1f4): In function `UdpTestSocket::OnRawData(char const*, unsigned int, sockaddr*, unsigned int)':
: undefined reference to `Socket::l2ip(in6_addr const&, std::basic_string<char,std::char_traits<char>, std::allocator<char> >&, bool)'
/tmp/ccl6Rgot.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x10): undefined reference to `Socket::Init()'
/tmp/ccl6Rgot.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x14): undefined reference to `Socket::Close()'
/tmp/ccl6Rgot.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x18): undefined reference to `UdpSocket::OnRead()'
/tmp/ccl6Rgot.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x1c): undefined reference to `Socket::OnWrite()'
/tmp/ccl6Rgot.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x20): undefined reference to `Socket::OnException()'
/tmp/ccl6Rgot.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x24): undefined reference to `Socket::OnDelete()'
/tmp/ccl6Rgot.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x28): undefined reference to `Socket::OnConnect()'
/tmp/ccl6Rgot.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x2c): undefined reference to `Socket::OnAccept()'
/tmp/ccl6Rgot.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x30): undefined reference to `Socket::OnLine(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/tmp/ccl6Rgot.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x34): undefined reference to `Socket::OnSSLInitDone()'
/tmp/ccl6Rgot.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x38): undefined reference to `Socket::OnConnectFailed()'
/tmp/ccl6Rgot.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x3c): undefined reference to `Socket::CheckConnect()'
/tmp/ccl6Rgot.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x40): undefined reference to `Socket::ReadLine()'
/tmp/ccl6Rgot.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x44): undefined reference to `Socket:SLCheckConnect()'
/tmp/ccl6Rgot.o(.gnu.linkonce.r._ZTV13UdpTestSocket+0x4c): undefined reference to `Socket::GetPort()'
/tmp/ccl6Rgot.o(.gnu.linkonce.t._ZN13UdpTestSocketD1Ev+0x16): In function `UdpTestSocket::~UdpTestSocket()':
: undefined reference to `UdpSocket::~UdpSocket()'
/tmp/ccl6Rgot.o(.gnu.linkonce.t._ZN13UdpTestSocketD0Ev+0x16): In function `UdpTestSocket::~UdpTestSocket()':
: undefined reference to `UdpSocket::~UdpSocket()'
/tmp/ccl6Rgot.o(.gnu.linkonce.r._ZTI13UdpTestSocket+0x8): undefined reference to `typeinfo for UdpSocket'
/tmp/ccADbXyN.o(.text+0x26): In function `main':
: undefined reference to `SocketHandler:ocketHandler(StdLog*)'
/tmp/ccADbXyN.o(.text+0x4c): In function `main':
: undefined reference to `SocketHandler::RegStdLog(StdLog*)'
/tmp/ccADbXyN.o(.text+0x8d): In function `main':
: undefined reference to `UdpSocket::Bind(unsigned short&, int)'
/tmp/ccADbXyN.o(.text+0x153): In function `main':
: undefined reference to `UdpSocket::AddMulticastMembership(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
/tmp/ccADbXyN.o(.text+0x22e): In function `main':
: undefined reference to `UdpSocket:etMulticastTTL(int)'
/tmp/ccADbXyN.o(.text+0x246): In function `main':
: undefined reference to `SocketHandler::Add(Socket*)'
/tmp/ccADbXyN.o(.text+0x264): In function `main':
: undefined reference to `SocketHandler:elect(long, long)'
/tmp/ccADbXyN.o(.text+0x272): In function `main':
: undefined reference to `SocketHandler::GetCount()'
/tmp/ccADbXyN.o(.text+0x296): In function `main':
: undefined reference to `SocketHandler:elect(long, long)'
/tmp/ccADbXyN.o(.text+0x2e4): In function `main':
: undefined reference to `SocketHandler::~SocketHandler()'
/tmp/ccADbXyN.o(.text+0x306): In function `main':
: undefined reference to `SocketHandler::~SocketHandler()'
/tmp/ccADbXyN.o(.gnu.linkonce.t._ZN9StdoutLogC1Ev+0x16): In function `StdoutLog:tdoutLog()':
: undefined reference to `vtable for StdoutLog'
collect2: ld returned 1 exit status
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dcode is offline Offline
1 posts
since Nov 2004
Feb 18th, 2005
0

Re: undefined reference errors when using C++ Sockets Library

Hi
When compiling and linking with gcc/g++ you should always enter the libs part last on your command line, like this:

g++ `Sockets-config` -o udpserver -I/usr/local/include/Sockets \
UdpTestSocket.cpp udpserver.cpp -L/usr/local/lib/ -lSockets -lpthread

I tested this right now and it works. Also note that I added -lpthread, since the library needs that.

Best regards
/ah
Reputation Points: 10
Solved Threads: 0
Newbie Poster
grymse is offline Offline
2 posts
since Feb 2005
Feb 18th, 2005
0

Re: undefined reference errors when using C++ Sockets Library

Quote originally posted by grymse ...
Hi
When compiling and linking with gcc/g++ you should always enter the libs part last on your command line, like this:

g++ `Sockets-config` -o udpserver -I/usr/local/include/Sockets \
UdpTestSocket.cpp udpserver.cpp -L/usr/local/lib/ -lSockets -lpthread

/ah
It's not a little late for this?
Reputation Points: 17
Solved Threads: 9
Posting Whiz in Training
frrossk is offline Offline
220 posts
since Sep 2004
Feb 18th, 2005
0

Re: undefined reference errors when using C++ Sockets Library

Quote originally posted by frrossk ...
It's not a little late for this?
Yes. Better late than not at all.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
grymse is offline Offline
2 posts
since Feb 2005

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: My Program runs but not correctly
Next Thread in C++ Forum Timeline: I really need help





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


Follow us on Twitter


© 2011 DaniWeb® LLC