使用提升线程时编译失败
Compile failed when using boost thread
这是我的代码:
#include <boost/thread.hpp>
#include <iostream>
using namespace boost;
void task1()
{std::cout << "This is task1!" << std::endl;}
void task2()
{std::cout << "This is task2!" << std::endl;}
int main ()
{
thread thread_1 = thread(task1);
thread thread_2 = thread(task2);
thread_2.join();
thread_1.join();
return 0;
}
我编译:
g++ test.cc -o test -lboost_thread -lpthread -lboost_system
编译失败:
/tmp/ccN9cPiI.o: In function `boost::system::generic_category()':test.cc(.text._ZN5boost6system16generic_categoryEv[_ZN5boost6system16generic_categoryEv]+0x7):
undefined reference to `boost::system::detail::generic_category_instance'
collect2: error: ld returned 1 exit status
这是怎么回事? 我的系统是 Ubuntu 18.04,boost 是 1_68.0。
我刚刚尝试了你的例子,它有效。我尝试了boost_1_66_0,并在 Ubuntu 上boost_1_65_1。
实际问题是提升本身,而不是您的安装。您可以在此处检查未解决的错误:
https://github.com/boostorg/system/issues/24
相关文章:
- 包含模板文件的递归会导致编译失败
- 提升 1.64 单元测试编译失败
- C++模板的模板编译失败
- 使用已删除的函数进行编译失败,并显示 uclibc
- MinGW-w64 编译失败,nullptr_t
- 使用提升线程时编译失败
- 编译花絮 g++, clang++, 使用 libboost -- g++8 编译失败时 g++7 成功;
- CMake + Qt,moc 编译失败,无法实现 QMetaObject 方法(编译器找不到基本 ui 对象的标头?
- 带有引用的std::tuple在clang中编译失败,但在gcc中编译失败
- 解决由于在哈希函数中使用了不完整的类型而导致的编译失败
- 将XCode升级到verison 11.1后,C++编译失败
- 添加类型名会导致程序编译失败
- 将 qi::lexeme 添加到灵气中的规则时编译失败
- 如果我在下面的代码中使用 list 而不是 vector,为什么在我尝试在迭代器之间执行减法的行中编译失败?
- 返回 std::stringstream - 编译失败
- 编译失败:strlen 不是 std 的成员
- MSBuidel - 将资源文件添加到项目后静态库编译失败
- C++ - 在 std::thread 中调用重载函数时编译失败
- QtWebEngine 到嵌入式 Linux 交叉编译失败
- 使用 glibc 2.7 包含路径编译失败