Boost 在linux(ubuntu)上使用Cmake增强

Boost 在linux(ubuntu)上使用Cmake增强,boost,linker,cmake,Boost,Linker,Cmake,这是我的CMakeLists.txt文件: add_definitions(-std=c++11) find_package(Boost 1.55.0 COMPONENTS filesystem REQUIRED) include_directories(${Boost_INCLUDE_DIRS}) add_executable(bst main.cpp) target_link_libraries(bst ${Boost_LIBRARIES}) 当我在我的build目录中执行cmake..时

这是我的
CMakeLists.txt
文件:

add_definitions(-std=c++11)
find_package(Boost 1.55.0 COMPONENTS filesystem REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(bst main.cpp)
target_link_libraries(bst ${Boost_LIBRARIES})
当我在我的
build
目录中执行
cmake..
时,
cmake
成功生成文件

但是,当我在
build
目录中运行
make
时,会出现以下错误:

amin@aminux:~/Documents/boost_test/build$ make
Scanning dependencies of target bst
[100%] Building CXX object CMakeFiles/bst.dir/main.cpp.o
Linking CXX executable bst
/usr/bin/ld: CMakeFiles/bst.dir/main.cpp.o: undefined reference to    symbol '_ZN5boost6system15system_categoryEv'
//usr/lib/x86_64-linux-gnu/libboost_system.so.1.55.0: error   adding       symbols: DSO missing from command line
 collect2: error: ld returned 1 exit status
make[2]: *** [bst] Error 1
make[1]: *** [CMakeFiles/bst.dir/all] Error 2
make: *** [all] Error 2

在我的
main.cpp
源文件中,我刚刚调用了
boost::filesystem::is_directory
函数,用于测试
boost

您还应该在CMakeLists.txt文件中添加boost::system library组件

查找_包(Boost 1.55.0组件文件系统系统必需)


添加系统组件find_包(需要Boost 1.55.0组件文件系统)-这应该会有帮助,谢谢这对我有用。我的朋友,你应该得到更多!