I'm trying to build a project using a static library, so that the binary can be used even if the library isn't installed. However, I get lots of errors about undefined symbols when I try to do so.
Looking at the library, I see it has tons of undefined symbols, even though it's a .a
static lib:
nm - u /usr/local/lib/libthis.a
....
U EVP_DigestFinal_ex
U EVP_DigestInit_ex
U EVP_DigestUpdate
U EVP_MD_CTX_cleanup
U EVP_MD_CTX_init
Those seem to be from openssl; others seem to be from libbzip2; etc.
Questions:
1. Why does the static (.a
) lib have dependencies on shared objects (e.g. libopenssl) that aren't statically compiled?
2. How do I solve this? Trying to manually add -lssl
doesn't seem to work. How do I get the binary to compile and not have external dependcies?
Just about every static library that you can build will have unresolved symbols, e.g.
As Marc Glisse pointed out, this a plain unresolved symbol, not a dependency on
libc.so
.There is no problem to solve here. When you link your binary, you get to decide which libraries to link statically, and which to link dynamically.
This should work:
Possibly you did something like
which is wrong: the order of libraries on the link line matters.
Most OSes support using fully-static binaries. Generally this should not be your goal: it makes for less portable binaries, and their use is strongly discouraged.
If you really do want to produce a fully-static binary, link it with
-static
flag.Because they are.
This is incorrect: most shared libraries support backward compatibility, e.g.
libc.so.6
version 2.22 will happily run executables linked against version 2.3.6 from 10 years ago.You need to pay attention to what you are doing:
If you look inside the shell script, you'll discover that it invokes
/usr/lib/firefox/firefox
, and that binary is dynamically linked: