Building & Running Qt programs on QtCreator for MacBook Pro M1
-
Hello,
I managed to install QtCreator for MacOS and load a Qt project on it. However, when I try to Build the project I get the following error :
"ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)"After searching about the problem, I ended up on : https://bugreports.qt.io/browse/QTBUG-85279
and tried to build 6.0 and 5.15 versions (using git checkout) using the options that are mentioned there. However, I never got it to build because of various errors.
Has anyone been able to build & run any program using QtCreator on MacOS with M1 processor?
Thanks in advance.
-
Has anyone been able to build & run any program using QtCreator on MacOS with M1 processor?
Yes, for me it "just works". Had no problem compiling or running any apps. I'm using Qt 5.15.2 and newest Xcode. And Rosetta2 of course. Apps compiled on M1 also work on other macs.
-
@sierdzio It was my fault. I used libelf library (after installing it manually) and this is causing the problem because it was not developed for macOS I suppose.
What's interesting is that I managed to compile a program using libelf manually using clang but QtCreator somehow fails to compile the same program (yields the error mentioned above).
To make this straight : I coded a test program using libelf library to check if libelf links correctly with my programs. I compiled my program using clang ...
-L/path/to/libelf_library -lelf -I/path/to/libelf_headers and it worked.But QtCreator fails to compile it, have you encountered something like this?
-
No I haven't, but I have not tried anything with libelf. How did you compile it in Qt Creator, what's your project file?
-
@sierdzio I re-built Qt (5.15) and Qt Creator from sources like this reddit post suggested : https://www.reddit.com/r/QtFramework/comments/ll58wg/how_to_build_qt_creator_for_macos_arm64_a_guide/
After building everything successfully, I ran QtCreator w/o using any other libraries. Just QApplication.
However, I still got :
"warning: ignoring file release/qtbase/lib/QtCore.framework/QtCore, building for macOS-x86_64 but attempting to link with file built for macOS-arm64"which was the reason for the "error : undefined symbols for x86_64".
My .pro file contains the following :
QT -= gui CONFIG += QMAKE_APPLE_DEVICE_ARCHS=arm64 CONFIG += c++11 console sdk_no_version_check CONFIG -= app_bundle SOURCES += \ main.cpp # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target
The project contains just a main.cpp file with the following code :
#include <QCoreApplication> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); return a.exec(); }
Finally, my kit configuration is the following :
https://ibb.co/vmn6t2V -
@kostasch said in Building & Running Qt programs on QtCreator for MacBook Pro M1:
CONFIG += QMAKE_APPLE_DEVICE_ARCHS=arm64
Ah so you are directly requesting
arm64
architecture. I am building forx86_64
.As the bug you've linked to suggests, building specifically for
arm64
is not yet ready. -
I really did nothing :D The same code which works on Linux, Windows and older macs simply worked for me on M1.