【发布时间】:2021-12-16 13:57:49
【问题描述】:
我正在使用一个无法为 Apple M1 编译的库,因此我决定编译它并使用 (Rosetta 2) for x86_64 使用它,我成功地按照this 为 x86_64 安装 brew 和 clang。
但是,当我编译我的项目并尝试将它与这个库链接时,我得到了这个错误:
ld: warning: ignoring file ..../libapronxx.a, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
...
ld: symbol(s) not found for architecture arm64
我尝试设置编译器和链接器标志(“-arch x86_64”),但仍然遇到同样的问题。
我的问题是:在 Apple M1 (arm) 上使用 cmake 为 macOS-x86_64 构建的正确方法是什么?
附加信息:我正在通过 CLion 使用 cmake。
更新: 我使用以下命令成功编译了我的项目:
# install a x86 cmake
arch -x86_64 /usr/local/bin/brew install cmake
...
# in the build directory
arch -x86_64 /usr/local/bin/cmake ..
make
arch -x86_64 ./my_exe
我还使用 -arch 标志指定了 clang 的架构
string(APPEND CMAKE_CXX_FLAGS_RELEASE " -arch x86_64 -O3")
string(APPEND CMAKE_CC_FLAGS_RELEASE " -arch x86_64 -O3")
# did the same for debug too
虽然这项工作正常,但我仍然不相信这是使用 cmake 为 macOS-x86_64 构建的正确方法,事实上我无法通过所有这些手动方法利用我的 IDE。
【问题讨论】:
-
@Tsyvarev,我可以成功编译库并使用它自己的测试文件(库使用 MakeFile),我希望从这个问题中得到的是为 macOS 编译的推荐方法-x86_64 来自苹果 ARM 机器,不管我做错了什么。
-
哦,对不起,我错误地解释了你的问题。重新阅读错误消息后,事情变得清晰了。
标签: c++ cmake linker cross-compiling apple-silicon