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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s