How to deploy a Qt application on Mac OS X using install_name_tool?

I'm having trouble packing my Qt application for Mac OS X.

I read the documentation on Deploying an Application on Mac OS X , but I'm still not sure what I'm doing wrong.

On my Mac, I have Qt5 installed on ~ / Qt5.1.0 / 5.1.0 / clang_64 (here is the bin / and lib / folder)

I have a Qt application called "renamer" on ~ / Documents / QtProjects / renamer /.

Using Qt Creator, I created a version of my application on ~ / Documents / QtProjects / build-renamer-Desktop_Qt_5_1_0_clang_64bit-Release. So, the first thing I did was run otool in my application:

 $ cd ~/Documents/QtProjects/build-renamer-Desktop_Qt_5_1_0_clang_64bit-Release $ otool -L renamer.app/Contents/MacOS/renamer 

Here is the result:

 renamer.app/Contents/MacOS/renamer: /Users/paul/Qt5.1.0//5.1.0/clang_64/lib/QtWidgets.framework/Versions/5/QtWidgets (compatibility version 5.1.0, current version 5.1.0) /Users/paul/Qt5.1.0//5.1.0/clang_64/lib/QtGui.framework/Versions/5/QtGui (compatibility version 5.1.0, current version 5.1.0) /Users/paul/Qt5.1.0//5.1.0/clang_64/lib/QtCore.framework/Versions/5/QtCore (compatibility version 5.1.0, current version 5.1.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 56.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0) 

The next thing I did was create the Frameworks directory inside my renamer.app package and copy the QtWidgets, QtGui and QtCore shells to the new directory:

 $ cd ~/Documents/QtProjects/build-renamer-Desktop_Qt_5_1_0_clang_64bit-Release $ mkdir renamer.app/Contents/Frameworks $ cp -R ~/Qt5.1.0/5.1.0/clang_64/lib/QtCore.framework renamer.app/Contents/Frameworks $ cp -R ~/Qt5.1.0/5.1.0/clang_64/lib/QtGui.framework renamer.app/Contents/Frameworks $ cp -R ~/Qt5.1.0/5.1.0/clang_64/lib/QtWidgets.framework renamer.app/Contents/Frameworks 

Then I ran install_name_tool to set the authentication names for the QtWidgets, QtGui, and QtCore frameworks:

 $ cd ~/Documents/QtProjects/build-renamer-Desktop_Qt_5_1_0_clang_64bit-Release $ install_name_tool -id @executable_path/../Frameworks/QtCore.framework/Versions/5/QtCore "renamer.app/Contents/Frameworks/QtCore.framework/Versions/5/QtCore" $ install_name_tool -id @executable_path/../Frameworks/QtGui.framework/Versions/5/QtGui "renamer.app/Contents/Frameworks/QtGui.framework/Versions/5/QtGui" $ install_name_tool -id @executable_path/../Frameworks/QtWidgets.framework/Versions/5/QtWidgets "renamer.app/Contents/Frameworks/QtWidgets.framework/Versions/5/QtWidgets" 

Then I made sure that the application knows where to find the library:

 $ cd ~/Documents/QtProjects/build-renamer-Desktop_Qt_5_1_0_clang_64bit-Release $ install_name_tool -change /../Frameworks/QtCore.framework/Versions/5/QtCore @executable_path/../Frameworks/QtCore.framework/Versions/5/QtCore "renamer.app/Contents/MacOS/renamer" $ install_name_tool -change /../Frameworks/QtGui.framework/Versions/5/QtGui @executable_path/../Frameworks/QtGui.framework/Versions/5/QtGui "renamer.app/Contents/MacOS/renamer" $ install_name_tool -change /../Frameworks/QtWidgets.framework/Versions/5/QtWidgets @executable_path/../Frameworks/QtWidgets.framework/Versions/5/QtWidgets "renamer.app/Contents/MacOS/renamer" 

Finally, since the structure of QtGui depends on the structure of QtCore and QtWidgets, depends on QtGui / QtCore, I also changed the link to QtGui and QtWidgets:

 $ install_name_tool -change /../Frameworks/QtCore.framework/Versions/5/QtCore @executable_path/../Frameworks/QtCore.framework/Versions/5/QtCore "renamer.app/Contents/Frameworks/QtGui.framework/Versions/5/QtGui" $ install_name_tool -change /../Frameworks/QtGui.framework/Versions/5/QtGui @executable_path/../Frameworks/QtGui.framework/Versions/5/QtGui "renamer.app/Contents/Frameworks/QtWidgets.framework/Versions/5/QtWidgets" $ install_name_tool -change /../Frameworks/QtCore.framework/Versions/5/QtCore @executable_path/../Frameworks/QtCore.framework/Versions/5/QtCore "renamer.app/Contents/Frameworks/QtWidgets.framework/Versions/5/QtWidgets" 

However, when I run otool -L renamer.app/Contents/MacOS/renamer , nothing changes, and I get the same result as before:

 renamer.app/Contents/MacOS/renamer: /Users/paul/Qt5.1.0//5.1.0/clang_64/lib/QtWidgets.framework/Versions/5/QtWidgets (compatibility version 5.1.0, current version 5.1.0) /Users/paul/Qt5.1.0//5.1.0/clang_64/lib/QtGui.framework/Versions/5/QtGui (compatibility version 5.1.0, current version 5.1.0) /Users/paul/Qt5.1.0//5.1.0/clang_64/lib/QtCore.framework/Versions/5/QtCore (compatibility version 5.1.0, current version 5.1.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 56.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0) 

I thought running otool -L renamer.app/Contents/MacOS/renamer will change the output to the new Qt paths, but it's still the same. I thought I followed all the steps, but this will not work. Did I skip a step or did something wrong? I can successfully deploy my program on Windows without problems, but I have problems with the Mac. How can I make the otool start display a new predefined path to search for QtCore, QtGui and QtWidgets frameworks from my renamer.app package?

I also tried using macdeployqt to deploy my application, but my application does not work when I rename / delete the Qt library set to ~ / Qt5.1.0 / 5.1.0 / clang_64. I tried the sudo macdeployqt renamer.app in my project folder after adding / bin to PATH. macdeployqt working fine, but when I rename / delete Qt, my application no longer works. I also ran otool after running macdeployqt , but the result did not change. I think macdeployqt copies the necessary Qt libraries to the application package, but it incorrectly changes where to look for qt libraries.

+4
source share
1 answer

As Stefano noted in his comment, install_name_tool can be very picky! You use a path like /../Frameworks/QtCore.framework/Versions/5/QtCore when you call insall_name_tool, while the link should be / Users / paul / Qt 5.10 / etc. (exactly the same as otool -L is shown) However, with Qt 5.2 using macdeployqt is much easier :)

+1
source

Source: https://habr.com/ru/post/1499492/


All Articles