Difference between revisions of "MacOS Troubleshooting"

From Qt Wiki
Jump to: navigation, search
(Remove duplicate title)
m (Jake Petroules moved page OS X Troubleshooting to MacOS Troubleshooting)
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Cleanup | reason=Auto-imported from ExpressionEngine.}}

Latest revision as of 21:58, 14 June 2016

This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine.
Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean.

Using Qt debug libraries

When using Qt frameworks, you might want to use the debug libraries instead of the release ones. This is done by setting the DYLD_IMAGE_SUFFIX environment variable to _debug.

export DYLD_IMAGE_SUFFIX=_debug

Unfortunately, on Snow Leopard, this causes your application to crash. The reason is that Apple system frameworks crash when using the debug libraries. To be able to use Qt in debug mode, you must remove the debug version of the library (or overwrite it with the release version).

$ sudo mv /usr/lib/libSystem.B_debug.dylib /usr/lib/libSystem.B_debug.dylib.backup $ sudo cp /usr/lib/libSystem.B.dylib /usr/lib/libSystem.B_debug.dylib // optional

Another solution is to change the install name information in the executable directly with install_name_tool (an utility shipped with Xcode). First of all, we can see a Qt program will link to several libraries and frameworks:

$ otool -L tst_qfontmetrics.app/Contents/MacOS/tst_qfontmetrics tst_qfontmetrics.app/Contents/MacOS/tst_qfontmetrics:

/Users/username/qt/lib/QtTest.framework/Versions/4/QtTest (compatibility version 4.8.0, current version 4.8.0)
/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 38.0.0)
/System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 37594.0.0)
/Users/username/qt/lib/QtGui.framework/Versions/4/QtGui (compatibility version 4.8.0, current version 4.8.0)
/Users/username/qt/lib/QtCore.framework/Versions/4/QtCore (compatibility version 4.8.0, current version 4.8.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 625.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)

We need to change the paths of QtTest, QtGui and QtCore here, which means:

$ install_name_tool -change /Users/username/qt/lib/QtCore.framework/Versions/4/QtTest /Users/username/qt/lib/QtCore.framework/Versions/4/QtTest_debug ./tst_qfontmetrics.app/Contents/MacOS/tst_qfontmetrics $ install_name_tool -change /Users/username/qt/lib/QtCore.framework/Versions/4/QtGui /Users/username/qt/lib/QtCore.framework/Versions/4/QtGui_debug ./tst_qfontmetrics.app/Contents/MacOS/tst_qfontmetrics $ install_name_tool -change /Users/username/qt/lib/QtCore.framework/Versions/4/QtCore /Users/username/qt/lib/QtCore.framework/Versions/4/QtCore_debug ./tst_qfontmetrics.app/Contents/MacOS/tst_qfontmetrics

In this way we can selectively use debug libraries for this program without affecting the system library. But changing this manually is cumbersome and error-prone, be sure to create a script for that if you are doing this constantly.