Deploying on macos failed.
-
I recently made a cross-platform tool that uses qt for the gui. I build the executable with cmake.
The CMakeFiles.txt looks like this:FIND_PACKAGE(Qt6 REQUIRED COMPONENTS Core Gui Widgets) FILE(GLOB_RECURSE SOURCES "src/*.h" "src/*.cpp") FILE(GLOB_RECURSE QRC_SOURCE_FILES "res/*.qrc") qt_add_resources(RESOURCE_FILES ${QRC_SOURCE_FILES}) ADD_EXECUTABLE(myapp ${RESOURCE_FILES} ${SOURCES} ${3RDPARTY_SOURCE}) SET_PROPERTY(TARGET myapp PROPERTY MACOSX_BUNDLE true) TARGET_LINK_LIBRARIES(myapp PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets)
After the cmake build was successful, I installed myapp.app into the
install/bin
directory, and I want to package my application for deployment with the commandmacdeployqt myapp.app
But it prints a lot of error messages and myapp.app doesn't run:ERROR: Cannot resolve rpath "@rpath/QtGui.framework/Versions/A/QtGui" ERROR: using QList("/Users/root/Documents/myapp/build/install/bin/lib") ERROR: Cannot resolve rpath "@rpath/QtCore.framework/Versions/A/QtCore" ERROR: using QList("/Users/root/Documents/myapp/build/install/bin/lib")
When I add the
-verbose=3
parameter, all errors look like thisI think the problem is from
@rpath
Log: copied: "/opt/homebrew/share/qt/plugins/imageformats/libqmacheif.dylib" Log: to "install/bin/myapp.app/Contents/PlugIns/imageformats/libqmacheif.dylib" Log: Using strip: Log: stripped "install/bin/myapp.app/Contents/PlugIns/imageformats/libqmacheif.dylib" Log: Using otool: Log: inspecting "install/bin/myapp.app/Contents/PlugIns/imageformats/libqmacheif.dylib" ERROR: Cannot resolve rpath "@rpath/QtGui.framework/Versions/A/QtGui" ERROR: using QList("/Users/ctvit/Documents/yang/myapp/build/install/bin/lib") ERROR: Cannot resolve rpath "@rpath/QtCore.framework/Versions/A/QtCore" ERROR: using QList("/Users/ctvit/Documents/yang/myapp/build/install/bin/lib")
How do I successfully package my app, any suggestions?
-
You are creating a bundle. Just
cd
into the target folder containing your .app as it was compiled (or move said .app to an empty location) and runmacdeployqt
.
I usually write a small deploy script for a final product, with code signing and everything but that all comes later. Absolute minimum that would make your bundle working:
cd
into the target where your .app is compiled
macdeployqt
with any optional parameters you might want.Please note that if you use any 3rd party libraries
macdeployqt
will not know about them. You should manually (or via script) include them yourself in appropriate location.