如何使用CMake链接Boost?



我使用自制软件在MacOS High Sierra 10.13.3上安装了Boost 1.60:brew install boost@1.60

我正在运行CLion 2018.1.1,我的工具链设置如下:捆绑的CMake 3.10.3,C++编译器/Library/Developer/CommandLineTools/usr/bin/c++,GNUMake 3.81

我的CMakeLists.txt文件如下:

cmake_minimum_required(VERSION 3.10)
project(xxx)
set(CMAKE_CXX_STANDARD 17)
add_executable(${PROJECT_NAME} main.cpp)
Set(BOOST_ROOT /usr/local/Cellar/boost@1.60/1.60.0)
find_package(Boost 1.60.0 REQUIRED COMPONENTS system filesystem regex)
if(Boost_FOUND)
message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
message(STATUS "Boost_VERSION: ${Boost_VERSION}")
include_directories(${BOOST_ROOT})
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})
endif()

构建似乎成功: -- Boost version: 1.60.0 -- Found the following Boost libraries: -- system -- filesystem -- regex -- Boost_INCLUDE_DIRS: /usr/local/Cellar/boost@1.60/1.60.0/include -- Boost_LIBRARIES: /usr/local/Cellar/boost@1.60/1.60.0/lib/libboost_system-mt.dylib;/usr/local/Cellar/boost@1.60/1.60.0/lib/libboost_filesystem-mt.dylib;/usr/local/Cellar/boost@1.60/1.60.0/lib/libboost_regex-mt.dylib -- Boost_VERSION: 106000

但是当我尝试执行时,我收到以下链接器错误

建筑的未定义符号x86_64: "boost::re_detail_106000::p erl_matcher, std::__1:::allocator>>, boost::regex_traits>>::construct_init(boost::basic_regex>> const&, boost::regex_constants::_match_flags)",引用自: boost::re_detail_106000::p erl_matcher, std::__1:::allocator>>, boost::regex_traits>>::p erl_matcher(std::__1::__wrap_iter, std::__1::__wrap_iter, boost::match_results, std::__1:::allocator>>>&, boost::basic_regex>> const&, boost::regex_constants::_match_flags, std::__1::__wrap_iter) in main.cpp.o "boost::re_detail_106000::p erl_matcher, std::__1::allocator>>, boost::regex_traits>>::match()",引用自: bool boost::regex_match, std::__1:::allocator>>, char, boost::regex_traits>>(std::__1::__wrap_iter, std::__1::__wrap_iter, boost::match_results, std::__1:::allocator>>>&, boost::basic_regex>> const&, boost::regex_constants::_match_flags) in main.cpp.o LD:在建筑x86_64中找不到符号

我做错了什么,我该如何解决这个问题?

我的错:在我的交叉构建中,我强迫libc ++而不是stdlibc ++ if (APPLE) # add_definitions(-D__GLIBCXX__)

最新更新