Mac OS X Troubleshooting
Using Qt debug libraries on Mac OS X 10.6 Snow Leopard
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
- /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)
- /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:
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.