MacOS Troubleshooting: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
=OS X Troubleshooting=
[[Category:HowTo]]


===Using Qt debug libraries on Mac OS X 10.6 Snow Leopard===
= OS X Troubleshooting =


When using Qt frameworks, you might want to use the debug libraries instead of the release ones. This is done by setting the <span class="caps">DYLD</span>_IMAGE_SUFFIX environment variable to _debug.
=== 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.
 
<code>export DYLD_IMAGE_SUFFIX=_debug<code>


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).
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).
</code>$ sudo mv /usr/lib/libSystem.B_debug.dylib /usr/lib/libSystem.B_debug.dylib.backup<br />$ sudo cp /usr/lib/libSystem.B.dylib /usr/lib/libSystem.B_debug.dylib // optional<code>


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:
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:
</code>$ otool -L tst_qfontmetrics.app/Contents/MacOS/tst_qfontmetrics<br />tst_qfontmetrics.app/Contents/MacOS/tst_qfontmetrics:<br /> /Users/username/qt/lib/QtTest.framework/Versions/4/QtTest (compatibility version 4.8.0, current version 4.8.0)<br /> /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)<br /> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 38.0.0)<br /> /System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 37594.0.0)<br /> /Users/username/qt/lib/QtGui.framework/Versions/4/QtGui (compatibility version 4.8.0, current version 4.8.0)<br /> /Users/username/qt/lib/QtCore.framework/Versions/4/QtCore (compatibility version 4.8.0, current version 4.8.0)<br /> /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)<br /> /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 625.0.0)<br /> /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)<code>


We need to change the paths of QtTest, QtGui and QtCore here, which means:
We need to change the paths of QtTest, QtGui and QtCore here, which means:
</code>$ 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<br />$ 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<br />$ 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<code>


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.
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.
===Categories:===
* [[:Category:HowTo|HowTo]]

Revision as of 10:02, 24 February 2015


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<code>

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.