1
votes

I installed Boost 1.60 on MacOS High Sierra 10.13.3 using homebrew: brew install [email protected]

I am running CLion 2018.1.1 with my toolchain setup as follows: bundled CMake 3.10.3, C++ Compiler /Library/Developer/CommandLineTools/usr/bin/c++ , GNU Make 3.81

my CMakeLists.txt file is as as following:

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/[email protected]/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()

Build seems to succeed: -- Boost version: 1.60.0 -- Found the following Boost libraries: -- system -- filesystem -- regex -- Boost_INCLUDE_DIRS: /usr/local/Cellar/[email protected]/1.60.0/include -- Boost_LIBRARIES: /usr/local/Cellar/[email protected]/1.60.0/lib/libboost_system-mt.dylib;/usr/local/Cellar/[email protected]/1.60.0/lib/libboost_filesystem-mt.dylib;/usr/local/Cellar/[email protected]/1.60.0/lib/libboost_regex-mt.dylib -- Boost_VERSION: 106000

But I get the following linker error when I try to execute:

Undefined symbols for architecture x86_64: "boost::re_detail_106000::perl_matcher, std::__1::allocator > >, boost::regex_traits > >::construct_init(boost::basic_regex > > const&, boost::regex_constants::_match_flags)", referenced from: boost::re_detail_106000::perl_matcher, std::__1::allocator > >, boost::regex_traits > >::perl_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::perl_matcher, std::__1::allocator > >, boost::regex_traits > >::match()", referenced from: 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: symbol(s) not found for architecture x86_64

What am I doing wrong, and how do I fix this ?

1
Run make VERBOSE=1 and post the link line. That will show the actual libraries you're trying to link against.Stephen Newell
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_link_script CMakeFiles/language_features.dir/link.txt --verbose=1 /Library/Developer/CommandLineTools/usr/bin/c++ -g -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/language_features.dir/main.cpp.o CMakeFiles/language_features.dir/test/cpp_sorter_test.cpp.o -o language_features -lgtest -lgtest_main /usr/local/Cellar/[email protected]/1.60.0/lib/libboost_system-mt.dylib /usr/local/Cellar/[email protected]/1.60.0/lib/libboost_filesystem-mt.dylib /usr/local/Cellar/[email protected]/1.60.0/lib/libboost_regex-mt.dylibuser127203

1 Answers

0
votes

My bad: in my cross-build I was forcing libc++ instead of stdlibc++ if (APPLE) # add_definitions(-D__GLIBCXX__)