Debug:‘boost::this_thread‘ has not been declared; undefined reference to ‘boost::this_thread...‘

Debug:'boost::this_thread' has not been declared; undefined reference to 'boost::this_thread...'

今天解决两个C++编译工程时的BUG。

问题1描述
编译到某个.cpp文件时,报'boost::this_thread' has not been declared; ,这个很明显是这个.cpp文件没有找到boost库里的这个函数的问题。

解决方法
在该.cpp文件或者对应的.h文件中,添加下面的头文件引用:

#include <boost/thread/thread.cpp>

再次编译时,就不会再报这个错误了。

问题2描述
编译完所有文件,开始链接时,报undefined reference to 'boost::this::hidden::sleep_until(timespec const&)',这个也是老错误了,多半是CMakeLists.txt文件里没有配置boost库,或者没有把boost库链接到target上。

解决方法
在CMakeLists.txt中添加配置:

find_package(Boost REQUIRED COMPONENTS thread)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIRS})
add_definitions(-DBOOST_ALL_DYN_LINK)

// 要把上面的库链接到可执行文件
target_link_libraries(main ${Boost_LIBRARIES})

再次编译链接,就不会报这个错了。

  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值