c++ - 尽管与 boost_system 链接,但对 boost::system::generic_category 的 undefined reference

标签 c++ boost linker boost-system

我的编译命令是:

g++ -I/home/foo/boost_1_56_0 -L/home/foo/boost_1_56_0/stage/lib -lboost_system -lboost_filesystem -lpthread -lboost_thread -lboost_system -lboost_filesystem -lpthread -lboost_thread main.cpp foo.cpp

我得到了对 boost::system::generic_category 的 undefined reference 尽管我将其与 -lboost_thread 链接,但仍出现错误.

我还得到了 undefined reference :

boost::system::generic_categorypthread_detach .

最佳答案

您应该在源文件之后指定库。

此外,与手动链接 libpthread.so 相比,更喜欢使用 -pthread

g++ -I/home/foo/boost_1_56_0 -L/home/foo/boost_1_56_0/stage/lib -pthread main.cpp foo.cpp -lboost_system -lboost_filesystem -lboost_thread

关于c++ - 尽管与 boost_system 链接,但对 boost::system::generic_category 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26317955/

相关文章:

C++ 使用模板来避免编译器检查 boolean 值

c++ - 为什么来自 boost::smart_ptr 的 &this_type::px 返回 1?

c - Mini OS : Linking the compiled & assembled . o 文件

c++ - 控制 Internet Explorer 以输入用户名/密码

c++ - 在文本文件中移动 C++

c++ - 递归矩阵乘法算法计算失败

c++ - boost::shared_ptr 的内容作为 set 的键?

c++ - 是否有可能在 C++ 中使用 std::atomic_flag 获得线程锁定机制?

c++ - (Visual Studio) 尝试将 Microsoft 库与 SFML 库静态链接时出现大量链接器错误

linux - 链接到调用其他共享库的共享库