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
/*************************************
***** Here's the code *************
*************************************/
#include <TcpSocket.h>
#include <SocketHandler.h>
class DisplaySocket : public TcpSocket {
public:
DisplaySocket(SocketHandler&);
void OnRead();
};
DisplaySocket::DisplaySocket(SocketHandler& h) : TcpSocket(h) {}
#define RSIZE 1024
void DisplaySocket::OnRead() {
TcpSocket::OnRead();
size_t n = ibuf.GetLength();
if (n > 0) {
char tmp[RSIZE];
n = (n > RSIZE) ? RSIZE : n;
ibuf.Read(tmp, n);
printf("Read %d bytes:\n", n);
for (size_t i = 0; i < n; i++) {
printf("%c", isprint(tmp[i]) ? tmp[i] : '.');
}
printf ("\n");
}
}
int main() {
SocketHandler h;
DisplaySocket *p = new DisplaySocket(h);
p->SetDeleteByHandler();
p->Open("localhost", 9002);
h.Add(p);
h.Select(1, 0);
while (h.GetCount()) {
h.Select(1, 0);
}
}
/*************************************
***** 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