架构x86_64的未定义符号:OS X,Boost Log,CMake

用户名

链接的另一个问题

OS X 10.9.5 x64

正在使用CMake工具链构建跨平台项目。使用提升。

将所有可执行文件与Boost Log链接时出错(肯定找到BOOST_PATH,Boost Test成功地进行了单元测试链接)

第一次尝试。使用C

gcc -v
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix

建筑助推

./bootstrap &&  ./b2 threading=multi link=static runtime-link=static install

成功完成

...updated 638 targets...

链接说明:

if( ("UNIX") AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") )

    # using Clang
    message("UNIX configuration, Clang")
    set(CMAKE_CXX_FLAGS "-std=c++11")
    set(CMAKE_EXE_LINKER_FLAGS "-std=c++11 -Wl")

将库链接到可执行文件

add_executable(${TARGET} ${SOURCES})
if( ("UNIX") AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") )

    # using Clang
    message("UNIX configuration, Clang")
    target_link_libraries(${TARGET}
        libhelpers.a
        libopenvpn_manager.a
        ${Boost_LOG_LIBRARY}
        ${Boost_LOG_SETUP_LIBRARY}
        ${Boost_SYSTEM_LIBRARY}
        ${Boost_FILESYSTEM_LIBRARY})

生成makefile:

cmake -DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++exit .

链接器输出(某些行已选择):

Undefined symbols for architecture x86_64:
 "boost::detail::get_tss_data(void const*)", referenced from:
      boost::log::v2s_mt_posix::core::add_thread_attribute(boost::log::v2s_mt_posix::attribute_name const&, boost::log::v2s_mt_posix::attribute const&) in libboost_log.a(core.o)
      boost::log::v2s_mt_posix::core::remove_thread_attribute(boost::log::v2s_mt_posix::attribute_set::iter<false>) in libboost_log.a(core.o)
      boost::log::v2s_mt_posix::core::get_thread_attributes() const in libboost_log.a(core.o)
      ...
  "boost::detail::set_tss_data(void const*, boost::shared_ptr<boost::detail::tss_cleanup_function>, void*, bool)", referenced from:
      boost::thread_specific_ptr<boost::log::v2s_mt_posix::core::implementation::thread_data>::reset(boost::log::v2s_mt_posix::core::implementation::thread_data*) in libboost_log.a(core.o)

      ...
  "boost::detail::thread_data_base::~thread_data_base()", referenced from:
      boost::detail::thread_data<boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > > >::~thread_data() in openvpn_test_app.cpp.o

…
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

第二次尝试。使用GCC

我如何使其默认

#!/bin/bash
cd /usr/bin
rm cc gcc c++ g++
ln -s /usr/local/bin/gcc-4.9 cc
ln -s /usr/local/bin/gcc-4.9 gcc
ln -s /usr/local/bin/c++-4.9 c++
ln -s /usr/local/bin/g++-4.9 g++

gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/4.9.1/libexec/gcc/x86_64-apple-darwin13.2.0/4.9.1/lto-wrapper
Target: x86_64-apple-darwin13.2.0
Configured with: ../configure --build=x86_64-apple-darwin13.2.0 --prefix=/usr/local/Cellar/gcc/4.9.1 --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-4.9 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-cloog=/usr/local/opt/cloog --with-isl=/usr/local/opt/isl --with-system-zlib --enable-version-specific-runtime-libs --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --disable-werror --with-pkgversion='Homebrew gcc 4.9.1' --with-bugurl=https://github.com/Homebrew/homebrew/issues --enable-plugin --disable-nls --enable-multilib
Thread model: posix
gcc version 4.9.1 (Homebrew gcc 4.9.1)

Build Boost与以前一样

链接说明

elseif( ("UNIX") AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") )

    # using GCC
    message("UNIX congiguration, GCC")
    set(CMAKE_CXX_FLAGS "-std=c++11 -pthread")
    set(CMAKE_EXE_LINKER_FLAGS "-std=c++11 -pthread")

将库链接到可执行文件的方式与使用Clang相同

target_link_libraries(${TARGET}
    libhelpers.a
    libopenvpn_manager.a
    ${Boost_LOG_LIBRARY}
    ${Boost_LOG_SETUP_LIBRARY}
    ${Boost_SYSTEM_LIBRARY}
    ${Boost_FILESYSTEM_LIBRARY})

生成makefile

cmake -DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++ .

链接器输出:

Undefined symbols for architecture x86_64:
"boost::detail::get_tss_data(void const*)", referenced from:
      boost::log::v2s_mt_posix::core::set_thread_attributes(boost::log::v2s_mt_posix::attribute_set const&) in libboost_log.a(core.o)
boost::log::v2s_mt_posix::core::get_thread_attributes() const in libboost_log.a(core.o)
      boost::log::v2s_mt_posix::core::remove_thread_attribute(boost::log::v2s_mt_posix::attribute_set::iter<false>) in libboost_log.a(core.o)
…
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
安德烈·谢马舍夫(Andrey Semashev)

您缺少的符号来自Boost.Thread,Boost.Log在多线程配置中使用该符号。您需要将“线程”组件添加到find_package行,并将Boost_THREAD_LIBRARY变量添加到target_link_libraries行。请注意,您可能需要确保target_link_libraries行中的库顺序正确,以避免链接由符号依赖项解析顺序引起的错误(应该最后指定叶依赖项)。例如:

find_package(Boost COMPONENTS log log_setup thread filesystem system)
target_link_libraries(${TARGET}
    ${Boost_LOG_SETUP_LIBRARY}
    ${Boost_LOG_LIBRARY}
    ${Boost_FILESYSTEM_LIBRARY}
    ${Boost_THREAD_LIBRARY}
    ${Boost_SYSTEM_LIBRARY}
)

根据您使用的功能,您可能需要类似地添加与Boost.Regex和Boost.DateTime的链接。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

架构x86_64抖动的未定义符号

架构x86_64的未定义符号:“ _fcloseall”

ProgressHUD:架构 x86_64 的未定义符号:

错误架构x86_64的未定义符号:

Boost.MPI 为架构 x86_64 提供未定义符号

Boost C ++的架构x86_64的未定义符号

如何修复架构x86_64,Boost Asio 1.58的未定义符号

架构x86_64的未定义符号->架构x86_64的未找到符号

使用多个文件时出现“架构 x86_64 的未定义符号”错误

架构x86_64的未定义符号:带有SFML的CMMotionManager

如何解决架构x86_64的未定义符号

Hello World中架构x86_64的未定义符号

架构x86_64的未定义符号是什么意思?

Xcode 6.3上架构x86_64的未定义符号

SFML 2.1架构x86_64错误的未定义符号

iOS中架构x86_64的未定义符号

Mac上的架构x86_64 C ++的未定义符号

由于架构 x86_64 的未定义符号,GLFW 的最小示例失败

架构x86_64的未定义符号:“ _ OBJC_CLASS _ $ _ HandBluetooth”,引用自:

架构x86_64的未定义符号:“ _rb_funcallv”

架构x86_64链接constexpr std :: array的未定义符号

反转字符串的代码:“架构 x86_64 的未定义符号”

找不到架构x86_64的未定义符号&& symbol(s)

iOS项目中架构x86_64的未定义符号

使用Json-C的架构x86_64的未定义符号

Pod安装期间出现Crashlytics错误“架构x86_64的未定义符号”

链接器错误:“架构 x86_64 的未定义符号”

xCode Cocoapods 构建失败“架构 x86_64 的未定义符号”

架构x86_64的未定义符号:“ vtkDebugLeaksManager :: vtkDebugLeaksManager()”,引用自: