GNU development under Mac OS X

Under Construction

This is a small guide to setup a development environment in Mac OS X (10.4) for doing GNU or other open-source software not specifically written for the Mac, but more for linux and other *nix's.

Get your ready

I would really suggest getting your terminal to behave properly, so swap some keys in 'Terminal', 'Window Settings...', 'Keyboard', namely the 'end' and 'shift end', 'home' and 'shift home', 'page down' and 'shift page down' and 'page up' and 'shift page up'.

Then edit the home key: delete all that is there and type the following keys:
ctrl + [, [, 1, ~ it should now say: \033[1~
Do the same for the end key, it should say: \033[4~

Then setup those keys to have, linux like, sane behaviour in bash and other readline aware programs, as root edit /etc/inputrc or as user ~/.inputrc:

# Be 8 bit clean.
set input-meta on
set output-meta on
set convert-meta off

# allow the use of the Home/End keys
"\e[1~": beginning-of-line
"\e[4~": end-of-line

# allow the use of the Delete/Insert keys
"\e[3~": delete-char
"\e[2~": quoted-insert

# mappings for "page up" and "page down" to step to the beginning/end 
# of the history
"\e[5~": beginning-of-history
"\e[6~": end-of-history

# alternate mappings for "page up" and "page down" to search the history
# "\e[5~": history-search-backward
# "\e[6~": history-search-forward

In the same arena, you can setup all your Cocoa Mac OS X programs to have the same behaviour with end / home / page up / page down keys, create a file ~/Library/KeyBindings/DefaultKeyBinding.dict that holds these values:

    /* Changes home/end keys to a sane behaviour */
    "\UF729" = "moveToBeginningOfLine:"; /* home */
    "\UF72B" = "moveToEndOfLine:"; /* end */
    "$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* shift + home */
    "$\UF72B" = "moveToEndOfLineAndModifySelection:"; /* shift + end */

    /* Changes pgup/pgdn keys to sane behaviour */
    "\UF72C" = "pageUp:"; /* pgup */
    "\UF72D" = "pageDown:"; /* pgdn */
    "$\UF72C" = "pageUpAndModifySelection:"; /* shift + pgup */
    "$\UF72D" = "pageDownAndModifySelection:"; /* shift + pgdn */

X11 and Mac OS X gcc

From your Mac OS X install cd's or DVD, install the extra package X11 for the X-server.

Next, install XCode (from Install the extra X11 package on there too. This gives you gcc and other development tools.

When compiling fails under Mac OS X it might be because of the newish compiler version. Switch compilers using gcc_select (gcc_select --help for help).

Darwin Ports

I really suggest using Darwin Ports, but Fink is also ok:

After you set that up you are ready to really start the development environment

The actual environment

I use a layered setup using environment variables, where executables and libraries use a fall-through setup.

So you don't have to touch your Mac OS X system stuff, nor the Darwin Ports stuff, all your tinkering will go to /local/.

in your ~/.profile set this:

# standard paths
export PATH="$HOME/bin:/local/bin:/opt/local/bin:$PATH"
export MANPATH="/local/man:/opt/local/share/man:$MANPATH"
export INFOPATH="/local/info:/opt/local/share/info:$INFOPATH"

# compiling
export CFLAGS="-I/local/include -I/opt/local/include -L/local/lib -L/opt/local/lib"
export LDFLAGS="-L/local/lib -L/opt/local/lib"

# pkg-config and autotools
export PKG_CONFIG_PATH="/usr/lib/pkgconfig:/usr/X11R6/lib/pkgconfig:/local/lib/pkgconfig:/opt/local/lib/pkgconfig"
export ACLOCAL_FLAGS="-I /local/share/aclocal -I /opt/local/share/aclocal -I /usr/share/aclocal"

# set default X display
export DISPLAY=''

Now, because libtool is not the GNU libtool, which is glibtool in Mac OS X, setup /local/bin/libtool to link to /usr/bin/glibtool:

$ ln -s /usr/bin/glibtool /local/bin/libtool
$ ln -s /usr/bin/glibtoolize /local/bin/libtoolize

Using it

Now you can use Darwin Ports to fetch standard libraries you need. And put any other source code under /local/ by using ./configure --prefix=/local.


Under linux and others LD_LIBRARY_PATH is needed to point to non-default places where shared libraries can be found. This is not the case under Mac OS X. DYLD_LIBRARY_PATH is only somewhat equivalent, you use it to force the loading of a library, but executables and shared libraries know the locations of the shared libraries they have been linked against.

Last modified: 2007-11-19 20:13 GMT