Header Article: Using libmimic in your Cocoa application
I am building a Universal (Intel/PPC) libmimic library on an Intel platform using Mac OS X 10.4.10 and with the aid of libraries installed via MacPorts. Based on your setup (PPC platform, fink, etc.) things might be slightly different for you but hopefully you’ll be able to make the adjustments once you see how I’ve done it.
Note: I’ve tested this on OS X 10.5 (Leopard) and it does not work as of 28th Oct, 2007.
libmimic needs the following libraries to be present: gperf, libiconv, expat, gettext, pkgconfig, glib. If you are using MacPorts, you should be able to install all of these by simply installing glib. The following command will do this:
$ sudo port install glib2 +universal
There are some caveats to the Universal build that will be explained later. Also, if you already have some of these libraries present on your system, you may have to manually uninstall and re-install them as a Universal build in order for the libmimic build to work. Additionally, if you later bundle all the necessary libraries needed for a Cocoa application that uses libmimic, all the libraries that you bundle into the application should be Universal libraries, if you want the application to work properly on both Intel and PPC platforms. For example, to re-install libiconv:
$ sudo port -f uninstall libiconv
$ sudo port install libiconv +universal
Now that you have glib installed, now on to libmimic itself. First, download and un-tar libmimic to a convenient location. I’ll use ~/libmimic for simplicity.
- Open a terminal session and change to your libmimic directory:
$ cd ~/libmimic
- Following Technical Note TN2137 on Apple’s website:
$ env CFLAGS="-I/opt/local/include -O -arch i386 -arch ppc" \
LDFLAGS="-arch i386 -arch ppc"
-O is for code optimization
-g is to generate debug info (I’ve left this one out, but you can add it if you need it)
- Now you can configure the Makefile for the Universal Build. The default installation path is /usr/local and you can change that to another location for testing.
--prefix=~/Desktop/libmimic_build
Keep in mind, however, that the final library will have headers which use this pathname so if you want to change the location, you can’t just move the files; you’d have to re-configure, re-build and re-install. Also remember that for multiple -arch targets, we need to use
--disable-dependency-tracking
$ ./configure --disable-dependency-tracking
- A problem arises because of the PPC architecture. During the configuration step, libtool gets copied (I’m not sure from where) and put into the libmimic directory. However, this version of libtool can’t handle the PPC architecture on an Intel platform. I’ve tried to figure out how to get the configuration process to put the right version, but haven’t been successful. So instead, I remove libtool and add a soft link to the version that will work:
$ rm libtool
$ ln -s /opt/local/bin/glibtool libtool
- Now we can proceed as usual:
$ make
$ sudo make install
If you’ve used the default installation directory, the following files get installed:
/usr/local/include/mimic.h
/usr/local/lib/libmimic.0.0.1.dylib
/usr/local/lib/libmimic.0.dylib (soft link)
/usr/local/lib/libmimic.a
/usr/local/lib/libmimic.dylib (soft lilnk)
/usr/local/lib/libmimic.la
/usr/local/lib/pkgconfig/libmimic.pc
Now let’s examine the dynamic library to make sure it’s a Universal library:
$ file /usr/local/lib/libmimic.0.0.1.dylib