问题描述
在Ubuntu16.04上安装好boost库之后,用CLion编写boost库相关代码,编写的时候,编辑器未提示错误,但是编译运行的时候,项目报错,查找资料后,发现需要在CMakeList.txt中显示的制定BOOST_ROOT
,并且需要find()
相关的组件,在运行的时候还要为目标文件链接boost library,最后才成功的使用了boost库。
解决方法
# 设置boost库的根路径
set(BOOST_ROOT "/usr/local/include/boost")
# 查找boost的功能模块
find_package(Boost 1.66.0 COMPONENTS log thread system regex date_time REQUIRED)
# 目标进行链接
target_link_libraries(thread ${Boost_LIBRARIES})