Linux applications because of the numerous and independent Linux version, in the production and use of engineering must be proficient in the following two points in order to effectively work and ideal to run.
1.Linux Standard library links three ways (full static, semi-static (libgcc,libstdc++), full dynamic) and their respective pros and cons.
2.Linux how to cleverly build achrive (*.A), and how to set the link options to resolve the GCC more specific link library order problem.
Full static:
1.-static-pthread-lrt-ldl
2. There is no standard library incompatibility issue for applications under different Linux versions.
3. The generated file is large, the application function is limited (cannot invoke the dynamic library, etc.)
Full dynamic
1.-pthread-lrt-ldl
2. The resulting file is the smallest of the three
3. It is relatively easy to make the application incompatible with the standard library dependencies under different Linux versions.
Semi-static (libgcc,libstdc++)
1.-static-libgcc-l.-pthread-lrt-ldl
2. Flexible, can adopt different link strategy for different standard library, so as to avoid incompatibility problem.
3. Combine the advantages of both full-static and full-dynamic link.
4. It is difficult to identify which libraries are prone to incompatibility problems, and now only rely on experience accumulation.
5. Some features will be lost due to the selected standard library version.
Linux Static Library link order problem and solution:
As mentioned in the GCC Handbook:
It makes a difference where in the command you write this option; The linker
Searches and processes libraries and object files in the order they is specified.
Thus, ' Foo.o-lz bar.o ' searches library ' z ' after file ' foo.o ' but before
' BAR.O '. If ' bar.o ' refers to functions in ' Z ', those functions is not being loaded.
To solve this problem of library link order, we need to add some link options:
$ (CXX) $ (linkflags) $ (OBJS)-xlinker "-(" $ (LIBS)-xlinker "-)"-o [email protected]
By placing all static libraries that need to be linked into the-xlinker "-(" and-xlinker "-)", you can automatically loop through all the static libraries during the g++ link process, thus resolving the original link order problem.
Related link Options:-xlinker
-xlinker option
Pass option as an option to the linker. can use this to supply system-specific
Linker options which GCC does not know how to recognize.
http://www.kxtry.com/archives/566
Three standard library link types