我的cmake中有文件系统:
find_package(Boost 1.63.0 COMPONENTS program_options system filesystem thread REQUIRED)
编译时,Found the following Boost libraries
和filesystem
包括在内。
一切都很好。但是,一旦我尝试包括:
#include <boost/filesystem.hpp>
我收到以下错误。这里发生了什么事?
CMakeFiles\runBasicBrimusTests.dir/objects.a(boost_filesystem_check.cpp.obj): In function `_static_initialization_and_destruction_0': C:/Users/b.karjoo/Documents/boost_1_63_0/boost/system/error_code.hpp:221: undefined reference to `boost::system::generic_category()' C:/Users/b.karjoo/Documents/boost_1_63_0/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()' C:/Users/b.karjoo/Documents/boost_1_63_0/boost/system/error_code.hpp:223: undefined reference to `boost::system::system_category()' collect2.exe: error: ld returned 1 exit status Brimus-Test\basic_tests\CMakeFiles\runBasicBrimusTests.dir\build.make:910: recipe for target 'Brimus-Test/basic_tests/runBasicBrimusTests.exe' failed CMakeFiles\Makefile2:293: recipe for target 'Brimus-Test/basic_tests/CMakeFiles/runBasicBrimusTests.dir/all' failed mingw32-make.exe[3]: *** [Brimus-Test/basic_tests/runBasicBrimusTests.exe] Error 1 mingw32-make.exe[2]: *** [Brimus-Test/basic_tests/CMakeFiles/runBasicBrimusTests.dir/all] Error 2 mingw32-make.exe[1]: *** [Brimus-Test/basic_tests/CMakeFiles/runBasicBrimusTests.dir/rule] Error 2 CMakeFiles\Makefile2:305: recipe for target 'Brimus-Test/basic_tests/CMakeFiles/runBasicBrimusTests.dir/rule' failed Makefile:169: recipe for target 'runBasicBrimusTests' failed mingw32-make.exe: *** [runBasicBrimusTests] Error 2
答案 0 :(得分:0)
您应该在cmake
中添加目标链接库。
find_package(Boost 1.63.0 COMPONENTS program_options system filesystem thread
REQUIRED)
target_link_libraries(mytarget
${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARY}
)