How to static link on OS X

In order to link to an archive library (sometimes also called static library), just add it to the link line:

gcc main.o ... -lfoo ...

The linker will search for libfoo.dylib, and then libfoo.a, which is all you need.

If you have both versions of the library, and want to link with an archive version in preference of the dynamic one, just specify the full path to the archive on the link line:

gcc main.o ... /path/to/libfoo.a ...

Leave a Comment