1

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

Jonathan Wakely
  • 166,810
  • 27
  • 341
  • 521
Breakdown
  • 1,035
  • 4
  • 16
  • 26
  • 1
    Libraries at the end. See http://stackoverflow.com/questions/9966959/linker-errors-when-compiling-against-glib/9966989#9966989 – hmjd Jan 03 '13 at 15:36
  • 1
    possible duplicate of [gcc undefined reference to](http://stackoverflow.com/questions/14042103/gcc-undefined-reference-to) and **many** other questions, libraries must be listed _after_ the objects that refer to them – Jonathan Wakely Jan 03 '13 at 15:42

1 Answers1

6

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.

Alex B
  • 82,554
  • 44
  • 203
  • 280