20050201
Creating OS X application bundles step by step
Introduction
This guide is the result of attempting to package a network visualiser (tcprose) I wrote so that it can be distributed as an application bundle. I gathered information from many places, and while I try to be accurate as possible should you notice any bugs feel free to contact me.
Step 1 - The folder hierachy
Each application bundle is on disk a file that ends in .app and contains a strict folder hierachy. The folder hierarchy is the form:
- application.app
- Contents
- Info.plist
- Frameworks
- dependent non-standard libraries
- MacOS
- executable binary
- Resources
- icons and other support files
- Figure out what libraries your application depends on, and figure out what libraries need to be distributed with the program. In order to see the dynamic libraries your binaries depend on, use the otool thus:
otool -L binary
In my case:solaris:~/code/tcprose steve$ otool -L tcprose tcprose: /sw/lib/libSDL-1.2.0.dylib (compatibility version 8.0.0, current version 8.1.0) /System/Library/Frameworks/Cocoa.framework/Versions /A/Cocoa (compatibility version 1.0.0, current version 9.0.0) /System/Library/Frameworks/OpenGL.framework/Versions /A/OpenGL (compatibility version 1.0.0, current version 1.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 71.1.1) /sw/lib/libpcap.0.dylib (compatibility version 0.8.3, current version 0.8.3) solaris:~/code/tcprose steve$
- Anything in /System or /usr can be safely assumed to be present on all default systems. Notice then the 2 libraries in /sw/lib. For those unfamiliar with fink, its where it installs all its packages. Those 2 libraries need to be copied into the Frameworks folder. Do be careful however that you copy the actual file, not the symbolic links. For example:
solaris:/sw/lib steve$ ls -l libpcap.0.dylib lrwxr-xr-x 1 root admin 19 20 Aug 03:35 libpcap.0.dylib -> libpcap.0.8.3.dylib solaris:/sw/lib steve$
Notice that libpcap.0.dylib is in fact a symlink to libpcap.0.8.3.dylib, thus you need to copy /sw/lib/libpcap.0.8.3.dylib, not /sw/lib/libpcap.0.dylib. - Once the required libraries have been copied into Frameworks folder, its time to do some linking manipulation. Use the install_name_tool to remapped the dynamically linked libraries so your binary links against the libraries in Frameworks folder. To do this you issue the command:
install_name_tool -change old_library_path new_library_path binary
In tcprose's case:solaris:/sw/lib steve$ install_name_tool -change /sw/lib/libpcap.0.dylib @executable_path/../Frameworks/libpcap.0.8.3.dylib ./tcprose
Notice the use of @executable_path: this is what makes it "tick". @executable_path will automatically map to the path where the executable is located. Now if you move the binary into the MacOS directory, it will link against the libraries you have copied into the Frameworks folder
Comments:
Links to this post:
<< Home
I tried to create an application for Ethereal (that comes with fink) but I failed. It must be more than just is said here. I get "can't open application "ethereal" because it may be damaged or incomplete".
:-(
:-(
If you can, email me the output of otool -L ethereal (ethereal in the MacOS directory) and also your iInfo.pList file.
My email is freespace \at gmail \. com.
Cheers,
Steve
My email is freespace \at gmail \. com.
Cheers,
Steve
Just wanted to say thanks for this fast introduction into bundleing macosx packages.
It took me some time to figure the best way out to access resources that are put into the bundle. Best way seems to use the argv[0] and cut off the everything before the last "/". That will give you a usable directory to access everything.
It took me some time to figure the best way out to access resources that are put into the bundle. Best way seems to use the argv[0] and cut off the everything before the last "/". That will give you a usable directory to access everything.
To previous commenter - Thats is an ingenious idea! Why one earth didn't I think of that!
I'll add it to the guide as a tip. Thank you for letting me also this helped you, made the effort worth while :-)
Cheers,
Steve
Post a Comment
I'll add it to the guide as a tip. Thank you for letting me also this helped you, made the effort worth while :-)
Cheers,
Steve
Links to this post:
<< Home

