简体   繁体   English

在Mac OSX上重新定位后修补Qt二进制文件的脚本

[英]Script to patch Qt binaries after relocation on Mac OSX

I'm building qt 5 from source. 我正在从源代码构建qt 5。 I'm wondering what is the easiest way to copy-paste qt binaries under MacOS. 我想知道在MacOS下复制粘贴qt二进制文件的最简单方法是什么。 If you run otool on any of the qt frameworks you'll see that all the dependencies are using absolute paths: 如果您在任何qt框架上运行otool,都会看到所有依赖项都使用绝对路径:

    bash-3.2$ otool -L QtWidgets 
QtWidgets:
    /Users/../Qt/qt5/qtbase/lib/QtWidgets.framework/Versions/5/QtWidgets (compatibility version 5.1.0, current version 5.1.1)
    /Users/../Qt/qt5/qtbase/lib/QtGui.framework/Versions/5/QtGui (compatibility version 5.1.0, current version 5.1.1)
    /Users/../Qt/qt5/qtbase/lib/QtCore.framework/Versions/5/QtCore (compatibility version 5.1.0, current version 5.1.1)
    /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 155.0.0)
    /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 19.0.0)
    /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
    /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/libc++.1.dylib (compatibility version 1.0.0, current version 65.1.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 744.18.0)
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
    /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 945.16.0)
    /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 45.0.0)
    /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1187.37.0)

When I copy qt binaries and link my application against that copy, it works but some dependent frameworks are taken from the old place. 当我复制qt二进制文件并将我的应用程序链接到该副本时,它可以工作,但是某些依赖的框架是从旧地方获取的。 The things become even worse when I try to move the binaries to another machine. 当我尝试将二进制文件移动到另一台计算机时,情况变得更糟。 I know that the problems can be fixed using install_name_tool but it's a lot of error-prone manual work. 我知道可以使用install_name_tool来解决问题,但这是很多容易出错的手动工作。 I'm wondering if there is a script which could help me in that? 我想知道是否有一个脚本可以帮助我?

After a long search on the Internet. 经过长时间的互联网搜索。 I discovered that Qt Installer Framework has necessary code to patch relocated Qt binaries under Mac OSX. 我发现Qt Installer Framework具有必要的代码来修补Mac OSX下重新定位的Qt二进制文件。 There was small problem to run that code, it's written in C++ that was not that easy to compile since it depends on Qt4 while I'm using Qt5.1. 运行该代码存在一个小问题,它是用C ++编写的,因此编译起来并不容易,因为在我使用Qt5.1时它依赖于Qt4。 Fortunately, it turned out that all the operations are available via command line. 幸运的是,事实证明所有操作都可以通过命令行进行。 To use that commands you need any installer created with Qt Installer Framework (Qt binary installer for Mac OSX is good enough) and to use the command below: 要使用该命令,您需要使用Qt Installer Framework创建的任何安装程序(适用于Mac OSX的Qt二进制安装程序就足够了)并使用以下命令:

./qt-mac-opensource-5.1.0-clang-offline.app/Contents/MacOS/qt-mac-opensource-5.1.0-clang-offline --runoperation "QtPatch" "mac"
"/Path/to/Qt/binaries/which/need/to/be/patched" "qt5"
========================================
Operation was successfully performed.

In case you get an error message which says "qmake is not a program" or something like that try to chmod qmake: 如果出现错误消息“ qmake不是程序”或类似的内容,请尝试对qmake进行chmod:

chmod 777 qmake

Note: this works with any QtIFW installer. 注意:这适用于任何QtIFW安装程序。 Play around with prebuilt version of QtIFW 试玩QtIFW的预构建版本

OK, that's it, that's the most straight forward way I found so far. 好的,就是这样,这是我到目前为止发现的最直接的方法。

If you are building QT5 from source anyways then static linking will solve some of your headaches. 如果您仍然从源代码构建QT5,那么静态链接将解决您的一些麻烦。

The original link listed broke. 列出的原始链接断开了。

To build QT statically add -static to the arguments when you run ./configure eg 要构建QT,请在运行./configure时将-static静态添加到参数中。

./configure -prefix /Developer/qt -qt-zlib -qt-libpng -qt-libjpeg -universal -sdk /Developer/SDKs/MacOSX10.4u.sdk -static -release

Compile with: make sub-src 编译: make sub-src

Install with: sudo make install 使用以下sudo make installsudo make install

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM