|
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. |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Linking order is important. You have to link dependent libraries My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
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. |
bamccaig
Member #7,536
July 2006
|
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) -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Edgar Reynaldo
Major Reynaldo
May 2007
|
If simple_server_main depends on ServerSocket, then ServerSocket has to be linked after simple_server_main so that the missing symbols in simple_server_main get linked in properly. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
bamccaig
Member #7,536
July 2006
|
That's the opposite of how I thought it worked. Though I've found that certain platforms/linkers are more picky than others. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
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. |
Edgar Reynaldo
Major Reynaldo
May 2007
|
gcc's linker ld only makes a single pass when linking. MSVC lets you get away with it though, as they read all the libraries first and then perform linking. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
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. |
bamccaig
Member #7,536
July 2006
|
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). -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
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. |
|