I have a MacBook M1 and have installed a library on my machine that was compiled for an x86 / Intel architecture. I have some source code that uses OpenMP. I would like to compile my code and link my executable to the x86 library using a clang compiler.
I am able compile source code with no x86 dependencies by following the instructions here, using an implementation of clang that is distributed with brew.
However when I try to compile with the -arch x86_64
argument and link to the x86 library I find that clang tries to link my executable to an OpenMP library that is built for the arm64 architecture.
Is it possible to install a version of clang on a MacBook M1 where the OpenMP libraries are built for x86 architectures?
Here is an example of an error that I get using my current setup, even when not linking to an x86 library.
Source code:
#include <omp.h>
int main()
{
return 0;
}
Call to compiler:
/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
Error message:
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 failed with exit code 1 (use -v to see invocation)