Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt 5.4 application bundled for OSX crashes when launched

I've been trying to bundle my Qt application as an OSX .app but encountered weird crashing right when I launch the bundled app. The application uses QtCore, QtGui, QtNetwork, QtWidgets, QtMultimedia and QtOpenGL frameworks, and Jack Audio Connection Kit as a dylib.

I added all following into xxx.app/Content/Frameworks/ and did name_install_tool to make sure everything is searched from @executable_path/../Frameworks/ and linking each of the frameworks to each other likewise.

When doing otool -L to the xxx.app/Content/MacOs/xxx I get the following:

@executable_path/../Frameworks/libjack.0.dylib (compatibility version 1.0.0, current version 1.0.0)
@executable_path/../Frameworks/QtMultimedia.framework/Versions/5/QtMultimedia (compatibility version 5.4.0, current version 5.4.0)
@executable_path/../Frameworks/QtNetwork.framework/Versions/5/QtNetwork (compatibility version 5.4.0, current version 5.4.0)
@executable_path/../Frameworks/QtCore.framework/Versions/5/QtCore (compatibility version 5.4.0, current version 5.4.0)
/System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
@executable_path/../Frameworks/QtGui.framework/Versions/5/QtGui (compatibility version 5.4.0, current version 5.4.0)
@executable_path/../Frameworks/QtOpenGL.framework/Versions/5/QtOpenGL (compatibility version 5.4.0, current version 5.4.0)
@executable_path/../Frameworks/QtWidgets.framework/Versions/5/QtWidgets (compatibility version 5.4.0, current version 5.4.0)
/System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/AGL.framework/Versions/A/AGL (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 104.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)

Which would imply everything is ok, but when I run the bundled app separated from the development environment, The application crashes:

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib          0x00007fff8fca9866 __pthread_kill + 10
1   libsystem_pthread.dylib         0x00007fff85c9a35c pthread_kill + 92
2   libsystem_c.dylib               0x00007fff85670b1a abort + 125
3   org.qt-project.QtCore           0x0000000109819159 qt_message_fatal(QtMsgType, QMessageLogContext const&, QString const&) + 9
4   org.qt-project.QtCore           0x000000010981a611 QMessageLogger::fatal(char const*, ...) const + 161
5   org.qt-project.QtGui            0x0000000109e13307 QGuiApplicationPrivate::createPlatformIntegration() + 6359
6   org.qt-project.QtGui            0x0000000109e1332b QGuiApplicationPrivate::createEventDispatcher() + 27
7   org.qt-project.QtCore           0x0000000109a34b11 QCoreApplication::init() + 113
8   org.qt-project.QtCore           0x0000000109a34a87 QCoreApplication::QCoreApplication(QCoreApplicationPrivate&) + 39
9   org.qt-project.QtGui            0x0000000109e1079e QGuiApplication::QGuiApplication(QGuiApplicationPrivate&) + 14
10  org.qt-project.QtWidgets        0x000000010a43653e QApplication::QApplication(int&, char**, int) + 206

And not crashing from missing frameworks or dylibs. The program works fine when running on development machine with Qt frameworks searched from /Users/xxx/Qt/5.4/clang_64/lib.

Also running the program so that only libjack dylib is searched from @executable_path/../Frameworks/ and Qt libs from /Users/xxx/Qt/.. works fine. So it's not libjack (perhaps).

If there is some framework/lib loading during runtime, how could I find out what? But then again, it should link to /Users/xxx/Qt/... and work?

like image 946
Joel Kivelä Avatar asked Nov 01 '22 07:11

Joel Kivelä


1 Answers

It's not a crash, it's a deliberate abort. qt_message_fatal() indicates that there's an error message printed on stderr that should give you details. Check for it in the "Console" application. Judging from the backtrace, I assume that it can't find the platform plugin (libqcocoa.dylib). Plugins are not linked at build time, so otool won't show them. You must bundle the platform plugin (and other plugins if you need them) with the application, where libqcocoa.dylib goes to Foo.app/Contents/PlugIns/platforms, and run the usual install_name_tool procedure on each plugin.

You might also want to try the "macdeployqt" tool shipped with Qt. That works fine at least for the not too complex deployment scenarios (in Qt 4 times it was worse)

like image 84
Frank Osterfeld Avatar answered Nov 15 '22 04:11

Frank Osterfeld