On shared library systems, libtool automatically generates an additional PIC object by inserting the appropriate PIC generation flags into the compilation command: burger$ libtool --mode=compile gcc -g -O -c foo.c
相当于:mkdir .libs 建立隐藏目录.libs 把用于产生动态库需要的 .o 文件放入.lib目录
gcc -g -O -c foo.c -fPIC -DPIC -o .libs/foo.o
gcc -g -O -c foo.c -o foo.o >/dev/null 2>&1
Note that Libtool automatically created ‘.libs’ directory upon its first execution, where PIC library object files will be stored.
在查看一些 .lo :
# foo.lo - a libtool object file
# Generated by ltmain.sh (GNU libtool) 2.2.6 #
# Please DO NOT delete this file!
# It is necessary for linking the library.
# Name of the PIC object.
pic_object='.libs/foo.o' //动态库与代码无关的.o
# Name of the non-PIC object.
non_pic_object='foo.o' //静态库的.o
链接:
静态库a23$ libtool --mode=link gcc -g -O -o libhello.la foo.lo hello.lo / -rpath /usr/local/lib -lm
a23$ libtool --mode=link gcc -g -O -o libhello.la foo.o hello.o
*** Warning: Linking the shared library libhello.la against the non-libtool
*** objects foo.o hello.o is not portable!
相当于:ar cru .libs/libhello.a
ranlib .libs/libhello.a
creating libhello.la
(cd .libs && rm -f libhello.la && ln -s ../libhello.la libhello.la)
Another complication in building shared libraries is that we need to
burger$ libtool --mode=link gcc -g -O -o libhello.la foo.lo hello.lo /
-rpath /usr/local/lib -lm
相当于:rm -fr .libs/libhello.a .libs/libhello.la
ld -Bshareable -o .libs/libhello.so.0.0 .libs/foo.o .libs/hello.o -lm
ar cru .libs/libhello.a foo.o hello.o
ranlib .libs/libhello.a
creating libhello.la
(cd .libs && rm -f libhello.la && ln -s ../libhello.la libhello.la)
burger$
Again, you may want to have a look at the ‘.la’ file in order
to see what Libtool stores in it. In particular, you will see that
Installing libraries on a non-libtool system is quite straightforward... just copy them into place:4
burger$ su Password: ********
Note that the libtool library libhello.la is also installed, to help libtool with uninstallation (see Uninstall mode) and linking (see Linking executables) and to help programs with dlopening (see Dlopened modules).
Here is the shared library example:
动态库安装
It is safe to specify the -s (strip symbols) flag if you use a BSD-compatible install program when installing libraries. Libtool will either ignore the -s flag, or will run a program that will strip only debugging and compiler symbols from the library.
Once the libraries have been put in place, there may be some additional configuration that you need to do before using them. First, you must make sure that where the library is installed actually agrees with the -rpath flag you used to build it.