g++的Boost静态链接问题

Boost static linking issue with G++

本文关键字:链接 问题 静态 Boost g++      更新时间:2023-10-16

我有一个应用程序,动态链接都可以,但是当我试图用静态链接编译时,我有下面的错误。

我的应用程序使用boost线程,asio

错误:

/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()'

和类似的错误,所有的源文件。

编译命令行

g++ -L/usr/lib/-lboostrongystem -lboost_thread -o newserver -static/usr/lib/libboost_thread。/usr/lib/libboostrongystem。一个stdafx.cpptest.cpp account .cpp…-lpthread化c++ 0 x

这很可能是由于你的链接顺序。Boost库首先出现在命令行中,在处理它们之后,链接器将在继续链接其他目标文件和库之前丢弃未引用的符号。

将boost库放在源代码之后,-lpthread之前。