目标提升::< library>已经有导入的位置+链接错误 [英] Target Boost::<library> already has an imported location + link errors

查看:98
本文介绍了目标提升::< library>已经有导入的位置+链接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Homebrew在MacOS Mojave上安装LLVM,Boost和CMake.将LLVM升级到9.0.0版本并将Boost升级到1.71.0之后,CMake(v3.15.3)开始抱怨各种库已经具有导入位置,例如:

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)

我的CMakeLists.txt的相关部分如下:

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
...

我查看了CMake生成的链接器命令,它似乎选择了非-mt.dylib Boost库:

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

我想这是CMake警告的提示.为什么会开始发生这种情况,该怎么办?

Which I suppose is what the CMake warning was suggesting. Why has this started happening and what can be done?

推荐答案

我问到有关Slack的CMake警告.正如彼得·迪莫夫(Peter Dimov)解释的那样:

I asked about the CMake warning on Slack. As explained by Peter Dimov:

这是因为自制软件会同时安装多线程和单线程boost

this is because homebrew installs both multithreaded and single-threaded boost

此外,由于boost 1.71的cmake支持存在问题,因此不尊重Boost_USE_MULTITHREADED

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

您可以定义Boost_NO_BOOST_CMAKE = ON来解决它

you can define Boost_NO_BOOST_CMAKE=ON to get around it

请参见 https://github.com/boostorg/boost_install/issues/13 ,应在下一发行版中对其进行修复.

See https://github.com/boostorg/boost_install/issues/13, it should be fixed in the next release.

2020年1月22日::通过brew upgrade boostboost更新到1.72并将set(Boost_USE_MULTITHREADED TRUE)添加到我的CMakeLists.txt中已经为我解决了此问题.

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.

这篇关于目标提升::&lt; library&gt;已经有导入的位置+链接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆