如果我没有放置-lboost_system
标志,我会理解此错误消息,但它确实在这里:
g++ -o build/myproject build/main/main.o -L/usr/local/boost/boost_1_52_0/boost/libs -L/usr/lib -Lbuild -L. -lboost_system -lboost_thread -lpthread -lboost_regex -lpq -lmylibrary build/libmylibrary.a(library.o): In function `__static_initialization_and_destruction_0(int, int)': library.cpp:(.text+0x25f): undefined reference to `boost::system::generic_category()' library.cpp:(.text+0x269): undefined reference to `boost::system::generic_category()' library.cpp:(.text+0x273): undefined reference to `boost::system::system_category()'
您是否知道我应该如何调查以解决问题? (我使用gcc 4.6.3)
答案 0 :(得分:26)
您链接图书馆的顺序很重要,如果您library.cpp
显然使用了boost_system
图书馆
library.cpp:(.text+0x25f): undefined reference to `boost::system::generic_category()'
library.cpp:(.text+0x269): undefined reference to `boost::system::generic_category()'
library.cpp:(.text+0x273): undefined reference to `boost::system::system_category()'
要解决这个问题,您应该将boost_system库移动到链接行的末尾
g++ -o build/myproject build/main/main.o -L/usr/local/boost/boost_1_52_0/boost/libs -L/usr/lib -Lbuild -L. -lboost_thread -lpthread -lboost_regex -lpq -lmylibrary **-lboost_system**
或者,将libmylibrary.so
构建为共享库并直接链接到boost_system
库。