MacOS – How do I deploy QT applications on Mac OS X using install_name_tool?

I am having trouble packaging my Qt application for Mac OS X.

I have read Deploying an Application on Mac OS X Documentation, but I am still not sure what I am doing wrong.

On my Mac, I installed Qt5 on ~/Qt5.1.0/51.0/clang_64 (this is bin/ and lib / Folder location)

I have a Qt application named “renamer” on ~/Documents/QtProjects/renamer/.

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

< p>

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

The results are as follows :

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/Q tCore (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)

Create a Frameworks directory in the .app package, and copy QtWidgets, QtGui and QtCore frameworks 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 run instal l_name_tool to set the identification name of QtWidgets, QtGui and QtCore framework:

$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 make sure that the application knows where to find the library:

< /p>

$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/QtG ui.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, due to the QtGui framework Depends on QtCore and QtWidgets framework depends on QtGui / QtCore, I also changed the reference of 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"

But when I run otool -L renamer.app/Contents/MacOS/renamer again later , Without any changes, I get the same output 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 think running otool -L renamer.app/Contents/MacOS/renamer will change the output to the new Qt path, but It’s still the same. I thought I followed all the steps, but it didn’t work. Did I miss a step or did something wrong? I was able to successfully deploy my program on Windows without problems, but I was having trouble on Mac. How can I make running otool display the newly set path so that I can find QtCore, QtGui and QtWidgets frameworks from my renamer.app package ?

I also tried to use macdeployqt to deploy my application, but when I rename/delete the Qt library installed under ~/Qt5.1.0/5.1.0/clang_64, my application does not It worked. After adding /bin to my PATH, I tried the command sudo macdeployqt renamer.app under the project folder. macdeployqt runs fine, but when I rename/remove Qt, my app no ​​longer runs .After running macdeployqt, I also ran otool, but the output did not change. I think macdeployqt copied the necessary Qt libraries to the application package, but did not change the location of the qt library correctly.

< div class="content-split">

As stefano pointed out in his comment, install_name_tool can be very picky! When calling insall_name_tool, you are using a path similar to /../Frameworks/QtCore.framework/Versions/5/QtCore, and the reference should be /Users/paul/Qt5.10/etc. (exactly as shown by otool -L ) But it is much easier to use macdeployqt with Qt 5.2 🙂

I am having trouble packaging my Qt application for Mac OS X.

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

On my Mac, I am at ~/Qt5.1.0/5.1.0 Qt5 is installed on /clang_64 (this is where the bin/ and lib/ folders are located)

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

Using Qt Creator, I built the release 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 on my application:

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

The results are as follows:

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/QtGu i (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)

What I will do next is to create one in the renamer.app package Frameworks directory, and copy QtWidgets, QtGui and QtCore frameworks 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/Cont ents/Frameworks
$cp -R ~/Qt5.1.0/5.1.0/clang_64/lib/QtWidgets.framework renamer.app/Contents/Frameworks

Then I run install_name_tool to set up QtWidgets, Identification name of QtGui and QtCore framework:

$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 make 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/../Framework s/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 QtGui framework depends on QtCore and the QtWidgets framework depends on QtGui / QtCore, I also Changed the references of 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_nam e_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 again later, nothing changes, I get the same output 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 think running otool -L renamer.app/Contents/MacOS/renamer will change the output to the new Qt path, but it is still the same. I thought I followed all the steps , But it doesn’t work. Am I missing a step or am doing something wrong? I was able to successfully deploy my program on Windows without problems, but I was having trouble on Mac. How can I make running otool display the newly set path so that I can find QtCore, QtGui and QtWidgets frameworks from my renamer.app package ?

I also tried to use macdeployqt to deploy my application, but when I rename/delete the Qt library installed under ~/Qt5.1.0/5.1.0/clang_64, my application does not It worked. After adding /bin to my PATH, I tried the command sudo macdeployqt renamer.app under the project folder. macdeployqt runs fine, but when I rename/remove Qt, my app no ​​longer runs .After running macdeployqt, I also ran otool, but the output did not change. I think macdeployqt copied the necessary Qt libraries into the application package, but did not change the location of the qt library correctly.

< p>

As stefano pointed out in his comment, install_name_tool can be very picky! When calling insall_name_tool, you are using a path similar to /../Frameworks/QtCore.framework/Versions/5/QtCore, and the reference should be /Users/paul/Qt5.10/etc. (exactly as shown by otool -L ) But it is much easier to use macdeployqt with Qt 5.2 🙂

Leave a Comment

Your email address will not be published.