?

Log in

No account? Create an account

something to hate about OS X

« previous entry | next entry »
Feb. 20th, 2006 | 02:35 pm

Every platform has its own private circle of shared (or dynamic) library hell.

For some reason the developers of OS X decided that applications should have the full pathname to whatever shared libraries are in it embedded in the application binary. This might be useful from the standpoint of performance, and may make it less likely that you'll load the wrong library.

However it makes building an application that uses shared libraries nightmarish. One might ask, if shared libraries are so bad, why not statically link it? And that would be a good idea if I could figure out why a statically linked Qt application built on an OS X 10.4 machine doesn't run on a 10.3.9 machine.

I eventually pieced together enough from the Qt docs to properly bless my archive.
#!/bin/sh
# This shell script is hereby placed into the public domain.
# Set all the stupid @executable_path variables on os x for a qt opengl application
# set QTDIR to the location of your qt library, and APP to the name of the application
export QTDIR=/usr/local/qt/4.1.0-shared
export APP=qtgl

for qt_lib in QtCore QtGui QtOpenGL; do
  framework_dir=${qt_lib}.framework/Versions/4.0
  framework=${framework_dir}/${qt_lib}
  mkdir -p ${APP}.app/Contents/Frameworks/${framework_dir}
  cp ${QTDIR}/lib/${framework} ${APP}.app/Contents/Frameworks/${framework}
  install_name_tool -id @executable_path/../Frameworks/${framework} \
                        ${APP}.app/Contents/Frameworks/${framework}
  install_name_tool -change ${QTDIR}/lib/${framework} \
                            @executable_path/../Frameworks/${framework} \
                            ${APP}.app/Contents/MacOS/${APP}
done

install_name_tool -change \
     ${QTDIR}/lib/QtCore.framework/Versions/4.0/QtCore \
     @executable_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore \
     ${APP}.app/Contents/Frameworks/QtGui.framework/Versions/4.0/QtGui
install_name_tool -change \
     ${QTDIR}/lib/QtCore.framework/Versions/4.0/QtCore \
     @executable_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore \
     ${APP}.app/Contents/Frameworks/QtOpenGL.framework/Versions/4.0/QtOpenGL
install_name_tool -change \
     ${QTDIR}/lib/QtGui.framework/Versions/4.0/QtGui \
     @executable_path/../Frameworks/QtGui.framework/Versions/4.0/QtGui \
     ${APP}.app/Contents/Frameworks/QtOpenGL.framework/Versions/4.0/QtOpenGL



Though other than this setting the frameworks stuff Qt is nice, my application builds on linux, OS X, and windows without any problem.

Link | Leave a comment |

Comments {0}