1
votes

I have an application, with dynamic linking all ok, but when i trying to compile with static linking, i have errors below.

My app uses boost thread, asio

Error:

/tmp/ccMj2fHI.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x237): undefined reference to `boost::system::get_system_category()'
test.cpp:(.text+0x243): undefined reference to `boost::system::get_generic_category()'
test.cpp:(.text+0x24f): undefined reference to `boost::system::get_generic_category()'
test.cpp:(.text+0x25b): undefined reference to `boost::system::get_generic_category()'
test.cpp:(.text+0x267): undefined reference to `boost::system::get_system_category()'
/tmp/ccnCWj1O.o: In function `__static_initialization_and_destruction_0(int, int)':
AccountSe.cpp:(.text+0x507): undefined reference to `boost::system::get_system_category()'
AccountSe.cpp:(.text+0x513): undefined reference to `boost::system::get_generic_category()'
AccountSe.cpp:(.text+0x51f): undefined reference to `boost::system::get_generic_category()'
AccountSe.cpp:(.text+0x52b): undefined reference to `boost::system::get_generic_category()'
AccountSe.cpp:(.text+0x537): undefined reference to `boost::system::get_system_category()'

And similar errors for all source files.

Compile command line:

g++ -L /usr/lib/ -lboost_system -lboost_thread -o newserver -static /usr/lib/libboost_thread.a /usr/lib/libboost_system.a stdafx.cpp test.cpp AccountSe.cpp ... -lpthread -std=c++0x

1
Libraries at the end. See stackoverflow.com/questions/9966959/…hmjd
possible duplicate of gcc undefined reference to and many other questions, libraries must be listed after the objects that refer to themJonathan Wakely

1 Answers

6
votes

It mostly likely is due to your linking order. Boost libraries appear first in the command line, and after processing them, the linker, will discard unreferenced symbols before proceeding to link other object files and libraries.

Put boost libraries after your sources and before -lpthread.