简体   繁体   中英

Boost static linking issue with G++

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM