Using CLion on Apple Silicon mac to target x86_64 or ARM architecture
Hello,
I'm a completely new user to CLion (previously using XCode on Mac OS and Visual Studio on Windows) and I've just installed it on my macbook with M1 apple silicon. Noticing that the latest CLion already supports apple silicon natively, I was able to compile and run c++ programs, as well as use external libraries that are built for ARM.
However, there are some projects where I use libraries that are only in x86 and not natively supported on ARM yet - in this case, in XCode I would be able to set running environment to Rosetta, to compile it as a x86 code, and run it with Rosetta emulator (including running all x86 dynamic libraries).
I wonder if CLion also supports a similar option, that is, targeting an x86_64 platform and running the debug session in Rosetta (despite that the IDE itself is now natively running on ARM)? If so, may I ask what flag should I add to e.g. CMakeLists or running configuration?
Thank you very much!
请先登录再写评论。
Hello!
Is it a CMake project? If yes, you can try setting -DCMAKE_OSX_ARCHITECTURES=x86_64.
Dear Anna, thanks a lot for your timely reply! May I ask how to add that flag to the CMakeList in the CLion project? Since it looks like a linker flag, I tried:
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -DCMAKE_OSX_ARCHITECTURES=x86_64")
However it still builds the project in arm64 (and when I link it to x86 dynamic libraries the build fails and the linker complains about incompatible architecture). May I ask what I might be doing wrong here with the architecture flag?
Thanks a lot!
Please either put -DCMAKE_OSX_ARCHITECTURES=x86_64 into `Preferences | Build, Execution, Deployment | CMake` > `CMake options`, or add
prior to the first
project()command in your CMakeLists.txt.Dear Anna, Thanks a lot for the reply! That solves the problem perfectly :) .
When I add this option, the profile becomes gray in the preferences dialog box, and is not shown at all in the targets pull-down in the tool bar.
I'm on CLion 2021.3.3.
Cris Luengo sorry for the delay in response. Does `Tools | CMake | Reset Cache and Reload Project` help?
Anna Falevskaya
Thanks, I eventually got it to work. I don't remember exactly what I did though, sorry.