编译 cmake 代码时获取"ld: symbol(s) not found for architecture x86_64"

Getting "ld: symbol(s) not found for architecture x86_64" when compiling cmake code

本文关键字:for found not architecture x86 代码 cmake 获取 ld symbol 编译      更新时间:2023-10-16

我正在尝试编译一个使用Boost的ROS包。代码在 Linux 上编译得很好,但在 OS X 上我收到错误

ld: symbol(s) not found for architecture x86_64

我通过brew安装了Boost,似乎它以64位安装(我的系统也是64位 - OS X 10.9),因为正在运行

file libboost_atomic-mt.dylib

输出

libboost_atomic-mt.dylib: Mach-O 64-bit dynamically linked shared library x86_64

在CMakeFiles.txt中,我已经尝试了编译和链接标志方面的几乎所有内容,尝试了-stdlib作为libc ++和libstdc++,以及-mmacosx-version-min作为从10.5到10.9的所有内容。例如,现在我有:

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++ -mmacosx-version-min=10.9")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libstdc++ -mmacosx-version-min=10.9")

此外,使用 -m64 构建会产生相同的错误,使用 -m32 构建会产生相同的错误,只是它说"......架构 i136"。

以下粘贴箱分别包含我的 CMake文件.txt和编译错误:

http://pastebin.com/0MD8T916 - CMakeFiles.txt

http://pastebin.com/v3vk9i2r - 错误

我没有解决这个问题的想法了...

感谢您的帮助!

您实际上并没有在项目中添加/链接 boost 库。

set(BOOST_COMPONENTS
    unit_test_framework
    program_options
    thread) # And other components you need
set(Boost_USE_STATIC_LIBS ON) # Easier to deploy elsewhere
set(BOOST_ROOT /usr/local/opt/boost) # Useful for boost from brew
set(BOOST_LIBRARYDIR /usr/local/opt/boost/lib64)
find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS})
include_directories(${Boost_INCLUDE_DIR})
target_link_libraries(<your target> ${Boost_LIBRARIES})