我正在使用一个无法为 Apple M1 编译的库,因此我决定编译它并使用 x86_64 的 (Rosetta 2) 使用它,我成功地按照此为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
Run Code Online (Sandbox Code Playgroud)
我尝试设置编译器和链接器标志(“-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
Run Code Online (Sandbox Code Playgroud)
我还使用 -arch …