I'm using Homebrew to install LLVM, Boost, and CMake on MacOS Mojave. After upgrading my LLVM to version 9.0.0 and Boost to 1.71.0, CMake (v3.15.3) started complaining about various libraries already having an imported location, such as:
CMake Warning at /usr/local/lib/cmake/boost_system-1.71.0/libboost_system-variant-shared.cmake:59 (message):
Target Boost::system already has an imported location
'/usr/local/lib/libboost_system-mt.dylib', which will be overwritten with
'/usr/local/lib/libboost_system.dylib'
Call Stack (most recent call first):
/usr/local/lib/cmake/boost_system-1.71.0/boost_system-config.cmake:43 (include)
/usr/local/lib/cmake/Boost-1.71.0/BoostConfig.cmake:117 (find_package)
/usr/local/lib/cmake/Boost-1.71.0/BoostConfig.cmake:182 (boost_find_component)
/usr/local/Cellar/cmake/3.15.3/share/cmake/Modules/FindBoost.cmake:443 (find_package)
src/CMakeLists.txt:673 (find_package)
The relevant section of my CMakeLists.txt
looks like:
set(REQUIRED_BOOST_LIBRARIES
system
filesystem
program_options
date_time
log_setup
log
iostreams
timer
thread
)
find_package (Boost 1.65 REQUIRED COMPONENTS ${REQUIRED_BOOST_LIBRARIES} REQUIRED)
message(STATUS "Boost include dir: " ${Boost_INCLUDE_DIR})
message(STATUS "Boost libraries: " ${Boost_LIBRARIES})
target_include_directories (myproject PUBLIC
${Boost_INCLUDE_DIR})
target_link_libraries (myproject ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
check_ipo_supported(RESULT ipo_supported OUTPUT output)
if(ipo_supported)
set_property(TARGET myproject PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
I'm also getting a bunch of link errors after successfully compiling my project, such as:
undef: __ZN5boost3log11v2_mt_posix5sinks17text_file_backend7consumeERKNS1_11record_viewERKNSt3__112basic_stringIcNS7_11char_traitsIcEENS7_9allocatorIcEEEE
undef: __ZN5boost3log11v2_mt_posix5sinks17text_file_backendD1Ev
undef: __ZN5boost3log11v2_mt_posix3aux17code_convert_implEPKwmRNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEEmRKNS5_6localeE
undef: __ZNK5boost3log11v2_mt_posix19attribute_value_set4findENS1_14attribute_nameE
...
Undefined symbols for architecture x86_64:
"boost::log::v2_mt_posix::sinks::text_file_backend::consume(boost::log::v2_mt_posix::record_view const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
boost::log::v2_mt_posix::sinks::synchronous_sink<boost::log::v2_mt_posix::sinks::text_file_backend>::consume(boost::log::v2_mt_posix::record_view const&) in lto.o
boost::log::v2_mt_posix::sinks::synchronous_sink<boost::log::v2_mt_posix::sinks::text_file_backend>::try_consume(boost::log::v2_mt_posix::record_view const&) in lto.o
"boost::log::v2_mt_posix::sinks::text_file_backend::~text_file_backend()", referenced from:
boost::detail::sp_counted_impl_pd<boost::log::v2_mt_posix::sinks::text_file_backend*, boost::detail::sp_ms_deleter<boost::log::v2_mt_posix::sinks::text_file_backend> >::~sp_counted_impl_pd() in lto.o
boost::detail::sp_counted_impl_pd<boost::log::v2_mt_posix::sinks::text_file_backend*, boost::detail::sp_ms_deleter<boost::log::v2_mt_posix::sinks::text_file_backend> >::~sp_counted_impl_pd() in lto.o
boost::detail::sp_counted_impl_pd<boost::log::v2_mt_posix::sinks::text_file_backend*, boost::detail::sp_ms_deleter<boost::log::v2_mt_posix::sinks::text_file_backend> >::dispose() in lto.o
"boost::log::v2_mt_posix::aux::code_convert_impl(wchar_t const*, unsigned long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, unsigned long, std::__1::locale const&)", referenced from:
void boost::log::v2_mt_posix::type_dispatcher::callback_base::trampoline<boost::log::v2_mt_posix::binder1st<boost::log::v2_mt_posix::output_fun, boost::log::v2_mt_posix::expressions::aux::stream_ref<boost::log::v2_mt_posix::basic_formatting_ostream<char, std::__1::char_traits<char>, std::__1::allocator<char> > >&>, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > >(void*, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&) in lto.o
...
I looked at the linker command that CMake generated and it appears to have selected the non-mt.dylib
Boost libraries:
clang++ ... /usr/local/lib/libboost_system.dylib /usr/local/lib/libboost_filesystem.dylib /usr/local/lib/libboost_program_options.dylib /usr/local/lib/libboost_date_time.dylib /usr/local/lib/libboost_log_setup.dylib /usr/local/lib/libboost_log.dylib /usr/local/lib/libboost_iostreams.dylib /usr/local/lib/libboost_timer.dylib /usr/local/lib/libboost_thread-mt.dylib /usr/local/lib/libhts.dylib /usr/local/lib/libboost_filesystem.dylib /usr/local/lib/libboost_date_time.dylib /usr/local/lib/libboost_atomic-mt.dylib /usr/local/lib/libboost_regex.dylib /usr/local/lib/libboost_chrono.dylib
Which I suppose is what the CMake warning was suggesting. Why has this started happening and what can be done?
In the properties dialog, select "Configuration Properties" and then "VC++ Directories". You will need to add the Boost include path to the "Include Directories" list. If you're using all header-only libraries then you're done. Otherwise, you will need to add the Boost library path to "Library Directories".
One of my current projects relies on Boost. Python, which requires a more recent version of Boost (1.64) than the one (1.54) provided by my Linux distribution (Ubuntu 14.04).
With Boost. Bimap you can create associative containers in which both types can be used as key.
I asked about the CMake warning on Slack. As explained by Peter Dimov:
this is because homebrew installs both multithreaded and single-threaded boost
in addition, due to an issue in boost 1.71's cmake support, Boost_USE_MULTITHREADED is not respected
I've fixed this for the next release
you can define Boost_NO_BOOST_CMAKE=ON to get around it
See https://github.com/boostorg/boost_install/issues/13, it should be fixed in the next release.
January 22, 2020: Updating boost
through brew upgrade boost
to 1.72 and adding set(Boost_USE_MULTITHREADED TRUE)
to my CMakeLists.txt
has fixed this problem for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With