我使用 qmake 在我的 MacBook 上编译我的 Qt 应用程序项目。
它需要一个名为 dylib 的 dylib libcore.dylib
,我把它放到了 dir$$OUT_PWD/../libs
中。
为了编译,我在.pro
文件中添加了这段代码
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../libs/release
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../libs/debug
else:unix: LIBS += -L$$OUT_PWD/../libs
LIBS += -lcore
为了跑步,我加了
macx {
QMAKE_LFLAGS += -Wl,-rpath,$$OUT_PWD/../libs
}
编译libcore.dylib
,我添加
win32:CONFIG(release, debug|release): DESTDIR = $$OUT_PWD/../libs/release
else:win32:CONFIG(debug, debug|release): DESTDIR = $$OUT_PWD/../libs/debug
else:unix: DESTDIR = $$OUT_PWD/../libs
macx {
QMAKE_SONAME_PREFIX = @rpath
}
完成后,我可以直接运行生成的应用程序。
但是当我使用 部署应用程序时macdeployqt
,会发生错误。
ERROR: Cannot resolve rpath "QtGui.framework/Versions/5/QtGui (compatibility version 5.5.0, current version 5.5.0)"
ERROR: using QSet("/Users/sjchao/Documents/QtBuild/project/debug/app/../libs")
ERROR: Cannot resolve rpath "QtCore.framework/Versions/5/QtCore (compatibility version 5.5.0, current version 5.5.0)"
ERROR: using QSet("/Users/sjchao/Documents/QtBuild/project/debug/app/../libs")
ERROR: Cannot resolve rpath "QtGui.framework/Versions/5/QtGui (compatibility version 5.5.0, current version 5.5.0)"
ERROR: using QSet("/Users/sjchao/Documents/QtBuild/project/debug/app/../libs")
ERROR: Cannot resolve rpath "QtCore.framework/Versions/5/QtCore (compatibility version 5.5.0, current version 5.5.0)"
ERROR: using QSet("/Users/sjchao/Documents/QtBuild/project/debug/app/../libs")
ERROR: Cannot resolve rpath "QtNetwork.framework/Versions/5/QtNetwork (compatibility version 5.5.0, current version 5.5.0)"
ERROR: using QSet("/Users/sjchao/Documents/QtBuild/project/debug/app/../libs")
rpaths 的 QSet 不包含 /Users/sjchao/Applications/Qt/5.5/clang_64/lib
!
但最终编译的 cmd 包含-Wl,-rpath,/Users/sjchao/Applications/Qt/5.5/clang_64/lib
! 没用?_
我看到了一点macdeployqt
源shared.cpp,然后我用otool -l
来看LC_RPATH
Load command 27
cmd LC_RPATH
cmdsize 112
path /Users/sjchao/Documents/QtBuild/project/debug/app/../libs (offset 12)
Load command 28
cmd LC_RPATH
cmdsize 64
path /Users/sjchao/Applications/Qt/5.5/clang_64/lib (offset 12)
426 while (i.hasNext()) {
427 if (i.next().contains("cmd LC_RPATH") && i.hasNext() &&
428 i.next().contains("cmdsize") && i.hasNext()) {
429 const QString &rpathCmd = i.next();
430 int pathStart = rpathCmd.indexOf("path ");
431 int pathEnd = rpathCmd.indexOf(" (");
432 if (pathStart >= 0 && pathEnd >= 0 && pathStart < pathEnd) {
433 QString rpath = rpathCmd.mid(pathStart + 5, pathEnd - pathStart - 5);
434 if (resolve) {
435 rpaths << resolveDyldPrefix(rpath, path, executablePath);
436 } else {
437 rpaths << rpath;
438 }
439 }
440 }
441 }
LC_RPATH
使用, rpaths
should contains运行此代码/Users/sjchao/Applications/Qt/5.5/clang_64/lib
,但错误消息说不。
我的 Qt 版本是 5.5.0,我已经使用 MaintenanceTool 将它更新到最新版本。
我应该怎么办?它是一个错误macdeployqt
吗?有什么建议么?