我有一台 MacBook M1,并在我的机器上安装了一个针对 x86 / Intel 架构编译的库。我有一些使用 OpenMP 的源代码。我想使用 clang 编译器编译我的代码并将我的可执行文件链接到 x86 库。
我可以按照此处的说明,使用与brew一起分发的clang实现来编译没有x86依赖项的源代码。
然而,当我尝试使用-arch x86_64参数进行编译并链接到 x86 库时,我发现 clang 尝试将我的可执行文件链接到为 arm64 架构构建的 OpenMP 库。
是否可以在 MacBook M1 上安装为 x86 架构构建 OpenMP 库的 clang 版本?
以下是我使用当前设置时遇到的错误示例,即使未链接到 x86 库也是如此。
源代码:
#include <omp.h>
int main()
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
调用编译器:
/opt/homebrew/opt/llvm/bin/clang++ -arch x86_64 omp_ex.cpp \
-L/opt/homebrew/opt/llvm/lib -Wl,-rpath,/opt/homebrew/opt/llvm/lib \
-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
Run Code Online (Sandbox Code Playgroud)
错误信息:
ld: in '/opt/homebrew/opt/llvm/lib/libunwind.dylib', building for macOS-x86_64 but attempting to link with file built for macOS-arm64
clang-12: error: linker command …Run Code Online (Sandbox Code Playgroud)