I read "Introduction to GCC" and he says the package has both .a and .so. gcc prefers a shared library. By default, the loader only searches for shared libraries in a predefined set of system directories, such as /usr/local/liband /usr/lib. If the library is not in one of these directories, it must be added to the download path, or you need to use the option -staticto force it to use the .a library. However, I tried the following:
vim hello.c:
#include <gmp.h>
#include <stdio.h>
int main() {
mpz_t x;
mpz_init(x);
return 0;
}
gcc hello.c -I/opt/include -L/opt/lib -lgmp (my gmp library is in opt)
./a.out
And it works. The book says that it should have the following error:
./a.out: error while loading shared libraries:
libgdbm.so.3: cannot open shared object file:
No such file or directory
(well, the book uses the GDBM example, but I used GMP, but that doesn't matter?)
LD_LIBRARY_PATH=/opt/lib, , , -static, a.out .
, , , ? , , , .