Under Linux. a/.so/.la target library difference

  

When compiling on the Linux platform, often encounter the problem of the target library, there are static libraries and dynamic libraries, a single understanding is not too difficult, but for complex Engineering, once mixed together, the understanding and call of the entire project will cause a lot of trouble, this article summarizes the differences between these common compilation results files.

1, format description

Under linux compilation, often encounter suffixes: .o.so.a.la.ko and other format files, although linux does not use the extension as the identification file The only basis for the format, but the specification convention is still there, as follows: ◾.o is the target object file, equivalent to the .obj file in windows a.a is a static library, which can be one or more .o together The shared library generated by lib.la for static connections is actually a configuration document. You can view the *.la file with $file *.la or use vi to view it. ◾.so is a shared library, similar to the windows platform dll file

Addition: There is also a .ko file extension, but it is a dynamic link file suffix used by the Linux kernel, belonging to the module file, used in The kernel module is loaded when the Linux system starts.

Second, create an instance

1, create a .o object file

$gcc -c test.c

generate test.o, skip the link Object, so it is not an executable file.

2. Create a .a static library file

$ ar -r libtest.a test1.o test2.o

3, create a dynamic library.so

$ gcc -Wall -fpic -shared test1.c test2.c -o libtest.so

Execution of the previous sentence, compile test1.c and test2.c to generate dynamic library file libtest.so

4, link library file

$gcc -Wall -fpic -shared -Ltest test3.c -o libtest.so

Compile test3.c and link with static libtest.a (The default is to find the file under /usr/lib) to generate the libtest.so dynamic library.

5, generate .la library

.la library is generally done through the makefile, of course, can also be through the command line, reference command:

$libtool --mode=link Gcc -o libmylib.la -rpath /usr/lib –L/usr/lib –la

libtool will search for the libmylib.a file and pass it to libmylib.la. More libtool help is as follows: Tst@Tst-PC /cygdrive/d/$ libtool --helpUsage: libtool [OPTION]... [MODE-ARG]...

Provide generalized library-building support services .

--config show all configuration variables--debug enable verbose shell tracing-n, --dry-run display commands without modifying any files--features display basic configuration information and exit--mode=MODE use Operation mode MODE--preserve-dup-deps don't remove duplicate dependency libraries--quiet, --silent don't print informational messages--no-quiet, --no-silentprint informational messages (default)--tag= TAG use configuration variables from tag TAG-v, --verbose print more informational messages than default--no-verbose don't print the extra informational messages--version print version information-h, --help, --help-all Print short, long, or detailed help message

MODE must be one of the following:

clean remove files from the build directorycompile compile a source file into a libtool objectexecute au Tomatically set library path, then run a programfinish complete the installation of libtool librariesinstall install libraries or executableslink create a library or an executableuninstall remove libraries from an installed directory

MODE-ARGS vary depending on the MODE. When passed as first Option,`--mode=MODE' may be abbreviated as `MODE' or a unique abbreviation of that.Try `libtool --help --mode=MODE' for a more detailed description of MODE.

When Reporting a bug, please describe a test case to reproduce it and include the following information:

host-triplet: i686-pc-cygwinshell: /bin/shcompiler: gcccompiler flags: -g -O2 -pipelinker: /usr /i686-pc-cygwin/bin/ld.exe (gnu? yes)libtool: (GNU libtool) 2.4automake: automake (GNU automake) 1.11.1autoconf: autoconf (GNU Autoconf) 2.68

Report bugs to <[email protected]>.GNU libtool home page: <http://www.gnu.org/software/libtool/>.General help using GNU software: http://www.gnu.org /gethelp/.

Copyright © Windows knowledge All Rights Reserved