2013-08-28 176 views
4

我有包裝我的Qt應用程序的Mac OS X如何使用install_name_tool在Mac OS X上部署Qt應用程序?

問題,我讀過Deploying an Application on Mac OS X的文檔,但我仍然不知道我做錯了。

在我的Mac,我已經安裝了QT5在〜/ Qt5.1.0/5.1.0/clang_64(這是哪裏的bin /和lib /文件夾所在)

我稱之爲 「重命名」 Qt應用程序在〜/ Documents/QtProjects/renamer /上。

使用Qt Creator,我在〜/ Documents/QtProjects/build-renamer-Desktop_Qt_5_1_0_clang_64bit-Release上構建了我的應用程序的發行版本。 所以,我做的第一件事是在我的應用程序運行otool

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

下面是結果:

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) 

我做的下一件事是創造我renamer.app包內的框架和目錄在QtWidgets,QtGui和QtCore框架複製到新目錄中:

$ 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 

然後,我跑到install_name_tool設置識別名稱對於QtWidgets,QtGui和QtCore框架:

$ 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" 

然後我保證應用程序知道在哪裏可以找到庫:

$ 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" 

最後,由於QtGui框架取決於QtCore和QtWidgets框架依靠QtGui/QtCore,我也改變了對參考和QtGui 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" 

然而,當我運行otool -L renamer.app/Contents/MacOS/renamer之後再次,沒有什麼變化我也得到了相同的輸出前:

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) 

我認爲運行otool -L renamer.app/Contents/MacOS/renamer將改變輸出到全新的Qt的路徑,但它仍然是相同的。我以爲我遵循了所有的步驟,但它不起作用。我錯過了一步或做錯了什麼?我能夠在Windows上成功部署我的程序,但沒有問題,但在Mac上遇到問題。我該如何做到這一點,以便運行otool將顯示從我的renamer.app包中查找QtCore,QtGui和QtWidgets框架的新設置路徑?

我也嘗試使用macdeployqt來部署我的應用程序,但是當我重命名/刪除安裝在〜/ Qt5.1.0/5.1.0/clang_64下的Qt庫時,我的應用程序不起作用。在將/ bin添加到PATH後,我嘗試了我的項目文件夾下的命令sudo macdeployqt renamer.appmacdeployqt運行良好,但是當我重命名/刪除Qt時,我的應用程序不再運行。運行macdeployqt後,我也跑otool,但輸出沒有改變。我認爲macdeployqt將必要的Qt庫複製到應用程序包中,但不會正確更改在哪裏查找qt庫。

+1

我今天早上安裝了Qt 5.1.1,並且能夠使用'macdeployqt'成功地部署我的應用程序。現在,當我重命名/刪除Qt時,我的應用程序仍然運行沒有任何問題。 – kimbaudi

+1

我認爲install_name_tool做了一個確切的字符串匹配,所以如果你使用更改,但甚至有單個字符差異(並且它是不相關的,如果它是一個路徑,就像你有//),那麼它不會工作 –

回答

1

正如stefano在他的評論中指出的,install_name_tool可以非常挑剔! 您正在使用/../Frameworks/QtCore之類的路徑。framework/Versions/5/QtCore,當調用insall_name_tool時引用應該是/Users/paul/Qt5.10/etc。 (完全如otool -L所示) 然而,使用macdeployqt的Qt 5.2更容易:)

相關問題