How to specify target architecture (x86_64 or arm/native) when building qmake project on M1?
-
I have a problem with one of my projects, and can't understand why it happens. When built on M1 Mac system, some targets are compiled for x86_64 and some for arm64. Naturally, I get a linker error for arch mismatch. How to specify the desired architecture with
qmake
and Qt 5.15.2?I have other C++ projects that build fine with the same Qt version on the same system.
-
Found it! The required compiler flag is
-arch x86_64
-
@Violet-Giraffe said in How to specify target architecture (x86_64 or arm/native) when building qmake project on M1?:
How to specify the desired architecture with qmake and Qt 5.15.2?
By calling qmake from Qt for that architecture.
-
@Violet-Giraffe hi,
Your other project likely uses libraries that are universal, meaning that they embed both x86_64 and arm64 symbols.
From memory, Qt 5.15.2 is single arch so you would need to build it yourself for the M1.
-
@SGaist, hi, thanks for chiming in! Let me clarify and expand on the question.
- I do not want to build for M1/ARM, I only want a pure x86_64 build. So it's no problem that Qt 5.15.2 doesn't support M1.
- Some of my own libraries, built by this project, were compiled for M1, and some others for x86_64. It's not even that my M1 binaries cannot be linked with x64 Qt - no, parts of my own project and my own code are being built inconsistently.
- The other project is also a C++ qmake subdirs project that uses Qt 5.15.2 and it builds fine, but that didn't help me to figure out why or what the problem is.
So in short - I don't want to target M1, I want to stop it from targeting M1 and force x86_64 instead.
-
Found it! The required compiler flag is
-arch x86_64
-
-
Excuse me, but I'm still having a similar problem. I did as you said, and ran
./qmake -set arch x86_64
, but nothing changed in action. Could you state more specifically what you did to get it fixed?More details:
I'm on an Intel Mac running macOS 12.6.8 and Xcode 14.2. The thing is, I had been using Qt 6.4.2 and Qt Creator 10.0.2, but after a series of Qt-related upgrades, I eventually ended up with Qt 6.5.2 and Qt Creator 11.0.0. Right now, Qt Creator cannot identify any Qt-related classes or identifiers, and I'm getting the same error as you did under Preferences, Kits, Qt Versions. However, projects are being built using the play button. -
@Mehrshad said in How to specify target architecture (x86_64 or arm/native) when building qmake project on M1?:
and I'm getting the same error as you did under Preferences, Kits, Qt Versions
What error is that?
What exact Qt version did you install? -
For Qt 6.5.3:
QMAKE_APPLE_DEVICE_ARCHS = x86_64
or
QMAKE_APPLE_DEVICE_ARCHS = x86_64 arm64
to create a universal binary, but I have not tested that. -
After creating a 64 bit arm64 binary for m1 on OSX Im getting an error with macdeployqt:
mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')
(mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')), '~/build/arm64/myapp/Contents/MacOS/QtQuickControls2.framework/Versions/5/QtQuickControls2' (no such file), '~build/arm64/myapp/Contents/Frameworks/QtQuickControls2.framework/Versions/5/QtQuickControls
When I look at the actual app it is a 64 bit arm app.
Using Qt 5.15.17 - latest and greatest.
When running the application in Qt Creator it runs fine. macdeployqt is not creating a correct binary for arm64. However it works fine for x86_64.
-
@SGaist to I actually was able to fix this.
I had to ensure I was using the arm 64-bit version of macdeployqt contained in /macos/
~/Qt5.15.17/5.15.17/clang_64/bin/macdeployqt
~/Qt5.15.17/5.15.17/macos/bin/macdeployqtIts important to use the correct one for the architecture you are building for.
Thank you.