I'm using a library that I cannot compile for Apple M1, so I have decided to compile it and use it using (Rosetta 2) for x86_64 which I successfully did following this to install brew and clang for x86_64.
However when I compile my project and try to link it against this library I get this error:
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
I have tried to the set compiler and linker flags ("-arch x86_64") but still got the same problem.
My question is: What is the proper way to build for macOS-x86_64 using cmake on Apple M1 (arm)?
Additional information: I'm using cmake via CLion.
UPDATE: I successfully compiled my project using the following commands:
# 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
I also specified the architecture for clang using -arch flag
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
While this work fine, I still don't believe it is the proper way to use cmake to build for macOS-x86_64, in fact I cannot take the advantages of my IDE with all this manual approach.
After checking CMake source code, I found that it is enough to set CMAKE_OSX_ARCHITECTURES
to x86_64
:
set(CMAKE_OSX_ARCHITECTURES "x86_64")
This is the cleanest way so far to solve this issue, and work straight forward with CLion too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With