c++ - 使用 G++ boost 静态链接问题

标签 c++ boost g++ static-linking undefined-reference

我有一个应用程序,动态链接一切正常,但是当我尝试使用静态链接编译时,出现以下错误。

我的应用使用 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/ -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

最佳答案

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

将 boost 库放在之后您的源代码和 -lpthread 之前。

关于c++ - 使用 G++ boost 静态链接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14142012/

相关文章:

c++ - 如何使用 boost::function_types::parameter_types 与 ClassTypeTransform

c++ - 如何修改 boost 多边形?

c++ - 使用 GCC 扩展定义

c++ - 更快的阅读和更快的处理

C++ 模板元编程, "static if"解决方法 - 可以改进吗?

c++ - 在窗口标题和消息框中显示错误的语言 : win32 application, opengl

c++ - 在不加入的情况下启动多个线程

c++ - 使用 boost 将 ffmpeg 输出通过管道传输到 ffplay 标准输入

c++ - 析构函数调用了不合适的库

c++ - GCC 可选预处理器一次输出和编译