Mixing Static and Dynamic Linkage

Using GNU tools you can mix static and dynamic linkage using:

gcc foo.o -Wl,-Bstatic -lstatic1 -lstatic2 -Wl,-Bdynamic -ldynamic1

Just be careful. The way the linker resolves symbols in static libraries is not what you might expect. It would be nice if it made one big symbol table and resolved everything. But it doesn’t work that way. Instead it reads from left to right. You may have to carefully arrange the order of libraries specified in your Makefile. You’ll want to arrange it so your static libraries with the most unresolved symbols appear to the left.

This entry was posted in Geek, Tips. Bookmark the permalink.

Leave a comment