The problem: writing a very simple Makefile to build a C shared library.
Let’s say we have just coded the most wonderful library foo
, which – not too surprisingly – has
greetings as its main purpose.
(Yeah, pretty impressive). We may also want to push it further, and test it using a quick C executable:
Here’s a simple Makefile with some nice features:
- the name and version of the library are just parameters
- it creates a shared object with a proper soname
- it compiles the library with debugging symbols, optimization and strict error checking
Nice. But what about our little test program? Let’s add some clutter to the minimal Makefile:
The complete version has a test
target which builds the foo_test
executable (only if needed) and
launches it (always). There is an intermediate step (the one involving ldconfig
) which takes care of
creating some symlinks needed to link against our foo
library.
References
Program Library HOWTO - The section about shared libraries
Shared objects for the object disoriented! - Quite old (2001) but very informative article
Simple makefile for compiling a shared object library file - Found on Stackoverflow (the library is written in C++, but the Makefile is adaptable to C with few modifications)