Metapkg:GNU Libtool on Mac OS X

From the Fink Wiki

Jump to: navigation, search


Back to the Metapkg Wiki

GNU Libtool support for Mac OS X has been steadily improving since the first OS X release. However, many software packages use old versions of GNU libtool, so the well-prepared OS X porter will know how to handle the various situations which arise.


Contents

GNU Libtool 1.3.5

Libtool 1.3.5 is the oldest version commonly encountered. If you are porting a package which relies on this version, you'll need patched versions of ltconfig and ltmain.sh. On the other hand, if you are trying to use libtool 1.3.5 itself to generate a new package (not recommended), you'll need a patch.


GNU Libtool 1.4.x

Libtool 1.4.x versions generally recognize Darwin/Mac OS X out of the box. However, there are problems with various versions, particularly as Mac OS X evolved and libtool worked to keep up.

One of the problems is with libtool-1.4.2 being unable to make "bundles" a.k.a. libtool modules with Apple's gcc 3.x. While it works fine with 2.9.5, Apple decided to disallow the -compatibility_version -current_version and -install_name flags when linking bundles with gcc3. One possible solution to this issue is to edit the generated configure script. Search configure for -bundle, and you should see something like the following:

archive_cmds='$nonopt $(test "x$module" = xyes && echo -bundle || echo -dynamiclib) $allow_undefined_flag -o $lib $libobjs $deplibs$linker_flags -install_name $rpath/$soname $verstring'

You will need to change this, here is a suggestion:

archive_cmds='$nonopt $(test x$module = xyes && echo -bundle || echo -dynamiclib) $allow_undefined_flag -o $lib $libobjs $deplibs$linker_flags $(test x$module != xyes && echo -install_name $rpath/$soname $verstring)'

Libtool 1.5.xx

Libtool 1.5 should work pretty well on Mac OS X nowadays. Only a few small known bugs remain in the 1.5 release, which are fixed in libtool CVS (due to become a libtool 1.6 release). The most significant change to note post-1.5 is that libtool now has proper support for the -framework flag. Depending on the version, previous libtools either passed it only with an -Xlinker or -Wl,<foo> flag, or even ignored it altogether (including not saving frameworks to the dependency_libs key in .la files!) It is also capable of checking the MACOSX_DEPLOYMENT_TARGET variable to enable some flags useful for handling undefined symbols on Mac OS X, namely the new -undefined dynamic_lookup ld option for Mac OS X 10.3, which allows libraries to be twolevel even if they have undefined symbols at compile time. See dyld and the Darwin Linker for more information on twolevel libraries.

Note that versions of libtool prior to 1.5 had ugly quoting problems due to the use of zsh as /bin/sh on Mac OS X 10.1 and earlier. zsh tended to remove too many quotes, avoiding the use of single or double quotes in the archive_cmds variable was the best way to avoid problems, however it didn't always work as expected, some libtool versions were released with quotes in archive_cmds, which worked with zsh but then failed on OS X 10.2 when bash was used as /bin/sh. Removing quotes from archive_cmds helps.

In case anyone cares the problem with zsh was solved for libtool-1.5 by putting in the following:

 if test -n "${ZSH_VERSION+set}" ; then
   setopt NO_GLOB_SUBST
 fi

All versions of libtool prior to 1.5.2 have a relinking bug when installing into a staging area using DESTDIR. The easiest fix for this is to simply disable relinking altogether, e.g.

 find . -name "*.la" | xargs perl -pi -e 's/^relink_command=.*/relink_command=/g'

This works on darwin because of the way search paths are encoded into libs and executables. Care must be taken to ensure that libtool only links to libraries it just built, not older installed versions of these libraries. Luckily, there is an easy way to do this too. We just need to change libtool's hardcode_direct variable to no, so a full build example would now become:

 perl -pi -e 's/hardcode_direct=yes/hardcode_direct=no/g' configure
 ./configure
 make
 find . -name "*.la" | xargs perl -pi -e 's/^relink_command=.*/relink_command=/g'
 make install DESTDIR=/path/to/packaging/dir

Revision History:

[This wiki page was started by Dave Morrison, based in part on Fink documentation written by Christoph Pfisterer and others.]

[[ 2003-09-16 Addition of libtool-1.4.2 problems by Peter O'Gorman, including a patch from Ben Hines]]

[[ 2003-10-15 General formatting and addition of more libtool 1.5 bits by Benjamin Reed]]

[[ 2004-04-12 Addition of relinking bug, Peter O'Gorman]]


Back to the Metapkg Wiki

Personal tools