Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Undefined references causing compilation to fail

Credits go to Edgar Reynaldo for helping out!
This thread is locked; no one can reply to it. rss feed Print
Undefined references causing compilation to fail
Bob Keane
Member #7,342
June 2006

I downloaded some files to play with networking in c++ and tried to compile but get the following errors:

g++ -o simple_server ServerSocket.o Socket.o simple_server_main.o
simple_server_main.o: In function `main':
simple_server_main.cpp:(.text+0x4a): undefined reference to `ServerSocket::ServerSocket(int)'
simple_server_main.cpp:(.text+0x69): undefined reference to `ServerSocket::accept(ServerSocket&)'
simple_server_main.cpp:(.text+0x88): undefined reference to `ServerSocket::operator>>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) const'
simple_server_main.cpp:(.text+0x9b): undefined reference to `ServerSocket::operator<<(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
simple_server_main.cpp:(.text+0xf2): undefined reference to `ServerSocket::~ServerSocket()'
simple_server_main.cpp:(.text+0x109): undefined reference to `ServerSocket::~ServerSocket()'
simple_server_main.cpp:(.text+0x11d): undefined reference to `ServerSocket::~ServerSocket()'
simple_server_main.o: In function `ServerSocket::ServerSocket()':
simple_server_main.cpp:(.text._ZN12ServerSocketC2Ev[_ZN12ServerSocketC5Ev]+0x1b): undefined reference to `vtable for ServerSocket'
collect2: error: ld returned 1 exit status
Makefile:11: recipe for target 'simple_server' failed
make: *** [simple_server] Error 1

I went to Ubuntu forums and they suggested adding #include <iostream> and the program will compile with warnings but it is not. My gcc version is gcc version 6.2.0 20161005 (Ubuntu 6.2.0-5ubuntu12). I'm thinking there is some version incompatibility, am I right? All files attached.

By reading this sig, I, the reader, agree to render my soul to Bob Keane. I, the reader, understand this is a legally binding contract and freely render my soul.
"Love thy neighbor as much as you love yourself means be nice to the people next door. Everyone else can go to hell. Missy Cooper.
The advantage to learning something on your own is that there is no one there to tell you something can't be done.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Bob Keane
Member #7,342
June 2006

Thanks for the help. It probably is something so simple.

By reading this sig, I, the reader, agree to render my soul to Bob Keane. I, the reader, understand this is a legally binding contract and freely render my soul.
"Love thy neighbor as much as you love yourself means be nice to the people next door. Everyone else can go to hell. Missy Cooper.
The advantage to learning something on your own is that there is no one there to tell you something can't be done.

bamccaig
Member #7,536
July 2006
avatar

Hmmm, if simple_server_main depends on ServerSocket I would expect the linker order to be as is... Unless maybe ServerSocket depended on Socket, but then the linker errors would be different... Did you build all of these objects yourself? Also, could you wrap the project into an archive so it's only a single attachment instead of many? (/me should modify acc.js to automatically do this using jszip)

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

bamccaig
Member #7,536
July 2006
avatar

That's the opposite of how I thought it worked. :o Though I've found that certain platforms/linkers are more picky than others.

Bob Keane
Member #7,342
June 2006

All good advice but the left hand/right hand frustration kicked in and I found references to ex_enet_server and ex_enet_client. Now if I can figure out why enet will not install...

By reading this sig, I, the reader, agree to render my soul to Bob Keane. I, the reader, understand this is a legally binding contract and freely render my soul.
"Love thy neighbor as much as you love yourself means be nice to the people next door. Everyone else can go to hell. Missy Cooper.
The advantage to learning something on your own is that there is no one there to tell you something can't be done.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Bob Keane
Member #7,342
June 2006

The program uses a make file to compile. Any ideas how to change the file or manually compile the programs to resolve the order?

By reading this sig, I, the reader, agree to render my soul to Bob Keane. I, the reader, understand this is a legally binding contract and freely render my soul.
"Love thy neighbor as much as you love yourself means be nice to the people next door. Everyone else can go to hell. Missy Cooper.
The advantage to learning something on your own is that there is no one there to tell you something can't be done.

bamccaig
Member #7,536
July 2006
avatar

Is the makefile static or generated? If it's static you can just open it in a text editor. If you don't know the makefile syntax that may not be entirely trivial, but they're just text files. You can probably figure it out or we can help. If it's generated then you may need to fix the source file(s) that generated it instead. Or you could settle for just fixing the generated makefile and having to manually fix it anytime you regenerate it...

Again, if you made it easier to download the files one of us might find ourselves motivated to try to build it. That might speed the process along. Alternatively, if you found this code somewhere online you could just refer us to there (I don't recall that coming up yet).

Bob Keane
Member #7,342
June 2006

By reading this sig, I, the reader, agree to render my soul to Bob Keane. I, the reader, understand this is a legally binding contract and freely render my soul.
"Love thy neighbor as much as you love yourself means be nice to the people next door. Everyone else can go to hell. Missy Cooper.
The advantage to learning something on your own is that there is no one there to tell you something can't be done.

Go to: