ALUT error resulting from bad link order

Alec Jacobson

December 03, 2013

weblog/

Link order dependency is one of my least favorite issues when writing C/C++. I ran into it again with the alut and OpenAL sound libraries. Trying to compile the alut example playfile.c, linking to alut after OpenAL like this:

gcc -I/usr/local/include/ -o playfile playfile.c -framework OpenAL -lalut

results in the following error when running:

Error loading file: 'The operation was invalid in the current ALUT state'

The "correct" order is fist alut then OpenAL, like this:

gcc -I/usr/local/include/ -o playfile playfile.c -lalut -framework OpenAL

Then the resulting binary executes properly.