There is a free software project that builds some static c++ libs and then
links them to make a binary. I’d like to separate the libraries out as
.so files for dynamic linking (so other projects might make use of
the lib). One library builds just fine, but when I try to link
it, I get “undefined reference” errors.
Those are easy to track down and fix (the code referenced those
methods in a .h file but the corresponding .cc file was not
included in the Makefile compile command). I am, however,
wondering why, as a general matter, a library would link just
fine as a static library but not as a dynamic library. What are
g++ and ld doing in one case but not the other?
Thanks much.
static libraries, created with ar are just a bunch of object files. ar is a very simple archiver. There are no dependencies resolved at link time, see the man page of ar.
Shared objects on the other hand, or dynamic libraries as you call them are a very different beast. They implement the ELF binary format and have a complicated ruleset. They also have initializing code, and some dependencies are resolved at link time. See http://www.akkadia.org/drepper/dsohowto.pdf and http://www.akkadia.org/drepper/goodpractice.pdf for a deeper introduction.