Differences between Linux. o a. So. La. Lo

Source: Internet
Author: User

O: compiled target file
-X/s3fm 'sh] x0
A:
Static library, in fact, is to pack a number of O files
K
Z3nouv
Pr0
So: dynamic link library (shared library) China's top electronic development network-the most professional electricity
Sub-Forum, blog of the most professional electronic engineer L &??, Z4i & G & S
V

R0 ^ MK zf5o "xc1c0
Lo:
The target file compiled using libtool is actually added to the o file with some information about top-level development of China Electronics.
Net ---- the most professional electronic forum, the most professional electronic engineer blog h5be
@ C .'}

La: library files compiled using libtool are actually text files that record information about dynamic and static libraries with the same name

Supplement: libtool

1. How libtool works
Axf &/P, mz0
Libtool
Is a common library supporting scripts that hide the complexity of dynamic libraries in a unified and portable interface. Using libtool's standard method, you can create and call dynamic libraries on different platforms. It can be considered
Libtool is an abstraction of GCC. It encapsulates GCC (or other compilers). You don't need to know the details, just tell libtool which libraries need to be compiled. libtool
Process the library dependencies and other details. Libtool only deals with libtool files with the suffix Lo and La.
G8s
I. a. Ths % W; x0
China's top electronic development network-the most professional electronic forum,
The most professional electronic engineer blog 2fj + x' KUY, l

Libtool
One of the main roles is to solve the library dependency problem in the process of compiling large software, and take over the heavy maintenance work of library dependency, thus releasing the human resources of programmers. Libtool
The first interface hides the differences in the names of libraries on different platforms, and generates an abstract suffix named libxx for the LA high-level library. la (actually a text file), and the dependency of the library on other libraries
System, all written in the La file. Dependency_libs in this file records all libraries that the library depends on (some of them are added in the form of a. La file); libdir indicates
Library installation location; library_names records the name of the Shared Library; old_library records the name of the static library.
V3te # TBq $ A0
Top electronic development network in China ---- the most professional electronic forum, the most professional electronic engineer blog kufn & RG % d

When compiling
If the following command is available during the process to the link stage:
#] TVT, C $ q9p0
China's top electronic development network-the most professional electronic forum, the most professional electronic engineer blog kax '& O
B $ x

$ Libtool -- mode = link GCC-O myprog-rpath/usr/lib
-L/usr/lib-La China's top electronic development network-the most professional electronic forum, the most professional electronic
Engineer blog $ J) f (J $ zeck9n

& PC
U7r )~ : Y0
Libtool
Search for LIBA. La in the/usr/lib path, and then read the name of the actual shared library (this name is recorded in library_names, such as LIBA. So) and
PATH (recorded in lib_dir, for example, libdir = '/usr/lib'), return parameters such as/usr/lib/LIBA. So to the GCC command line that is triggered.
China's top electronic development network-the most professional electronic forum, the most professional electronic engineer blog
H
K, p7qu} ujbb

-]/& Kyg0
For example
If LIBA. So depends on the Library/usr/lib/libb. So, dependency_libs = '-L/usr/lib will be available in LIBA. La.
-Lb 'or dependency_libs ='/usr/lib/libb. la'. If it is the former, it directly calls "-l/usr/lib
-Lb "is used as a parameter to pass to the GCC command line. If it is the latter, libtool will use/usr/lib/libb. read the actual libb from LA. so library name and path, and then group
The merging parameter "/usr/lib/libb. So" is passed to the GCC command line. China Top electronic Development Network
---- The most professional electronic forum, the most professional electronic engineer blog + a6h; E4A]
[5ze/s

`
S-m6d d1dn $ t0
When the file to be generated is libmylib. LA, for example:
U/g/} n} k0h (zo0

R
Qe {nxo9y: _ 0
$ Libtool -- mode = link GCC-O libmylib. La-rpath
/Usr/lib-L/usr/lib-La top electronic development network in China ---- the most professional Electronics
Forum, the most professional blog of Electronic Engineers
B # To, bu + PVB # F % v

Top electronic development network in China ----
"Qk" t, D * C2R @

The search of the dependent library is similar, but at this time, it will follow the corresponding rules
The corresponding shared library and static library are generated. China's top electronic development network-the most professional electronic forum, the most professional electronic
Engineer blog | 9e (P & G6? 6n'/kW

China Electronic Summit
Development Network ---- the most professional electronic forum, the most professional electronic engineer blog N5 @ 1fop8yq $ OJ

Note: When libtool is linked
Only the libtool file with the suffix la is involved. The actual library file name, library installation path, and dependency are read from the file.
W. djp? -J9j
Saq0
China's top electronic development network-the most professional electronic forum, the most professional Electronic Engineering
Instructor blog f4g3s 'nx! Qpc7f

2 Why use-wl, -- rpath-link-wl, dir? Top electronic development network in China ---- the most professional electronic forum and the most professional electronic engineer blog orbyf

Enable
It seems that there is no problem to solve the compilation problem using libtool: the Library name, path, and dependency have been well solved. But don't be so anxious to draw conclusions. An obvious problem is: not all
Libraries are all compiled using libtool.
O: LP ']'? B0
China's top electronic development network-the most professional electronic forum, the most professional electronic engineer Blog & cvqp
Z'jkf

For example, in the example above, China's top electronic development network-the most specialized
Yfnz0lr, e-forum of the industry and blog of the most professional e-engineer */

4G "BJD ~ X5z0
$ Libtool -- mode = link GCC-O myprog-rpath
/Usr/lib-L/usr/lib-La top electronic development network in China ---- the most professional Electronics
Blog of Forum and most professional electronic engineer tz0 @ 9ve kN

China Electronics
Top Development Network ---- the most professional electronic forum, the most professional electronic engineer blog 2 | I/ou5 G. tj

If LIBA. So is not used
The libtool cannot find the LIBA. La file (this file does not exist ). In this case, libtool only sets "-l/usr"
/Lib-La "is passed to the GCC command line as a parameter.
M $/2 S. Q6? 0

Qg1lfe $ l5g0
Test
Consider the following situations: To compile and generate myprog from the myprog. o file, it depends on library LIBA. So (generated using libtool), and LIBA. So depends on
Libb. So (libtool is not used to generate libb. So). For some reason, A's dependency on B is not written to LIBA. La. Compile with the following command:

Y0q5k �g, _ G0
Top electronic development network in China ---- the most professional electronic forum, the most professional electronic engineer blog-np7r
Q3c3p7m $ {o

$ Libtool -- mode = link GCC-O myprog-rpath/usr/lib
-L/usr/lib-la
D0d?
JK 'q0

3/$ ou/B * O4]
C ~ 0
The GCC command line inspired is similar to the following: Top electronic Development Network of China ---- the most specialized
Industry e-forum, the most professional electronic engineer blog s2gb8? T |

China
Top electronic development network ---- the most professional electronic forum, the most professional electronic engineer blog G-FH]-h8al]? H]


Gcc-O myprog/usr/lib/LIBA. So
U {"V '0d2ns0
Top electronic development network in China ---- the most professional electronic forum, the most professional electronic engineer blog; o6czb $ wri

By
LIBA. So depends on libb. So (this dependency can be seen by readelf reading the ELF File of LIBA. So), but it does not appear in the preceding command line.
Libb. So, so problems may occur.
)]; V 'tc -_
Hob0

} L ~ 6jm0

It is "possible" because GCC cannot find a library (such as the above LIBA. so) other dependent libraries (such as libb. so), the linker will press
Search for the desired shared library under certain paths according to a certain policy:
* HN 'q-| K0
Top electronic development network in China ---- the most professional electronic forum, the most professional electronic engineer blog Q @ FX {-u4g
SAF

1. All search paths specified by the '-rpath-link' option. Top electronic development network in China ---- the most professional electronic forum and the most professional electronic engineer blog) b8d
GBR % m (} b0y

% R "[I, X # Q} 0
2.
All search paths specified by '-rpath.
The difference between '-rpath' and'-rpath_link 'is that the path specified by'-rpath' is included in the executable file and used during runtime,
The '-rpath-link' option only works during connection.
_
B + x2m {2n0
China's top electronic development network-the most professional electronic forum, the most professional
E-engineer blog) | Z % oq3] h'5n

3. In an elf system,
If the '-rpath' and 'rpath-link' options are not used, the content of the environment variable 'LD _ run_path' will be searched. it only works for local connectors. top electronic development network in China ---- the most professional electronic forum and the most professional electronic engineer blog [�u "eh1u
B0a-L

China's top electronic development network-the most professional electronic forum, the most professional electricity
Sub-engineer blog ba7mf. s! C, la

4. On SunOS, the '-rpath' option is not used,
Only search for all Directories specified by '-l'. Top electronic Development Network of China ---- the most professional electronic forum, the most professional
E-engineer blog {imw;

6e @ * I ^ '; @ 0
5.
For a local connector, the content of the environment variable 'LD _ LIBRARY_PATH 'is searched.
Sub-top development network ---- the most professional electronic forum, the most professional electronic engineer blog 4N! K73796z6?

, {A8 | Cu '/} o
U: t0
6. For a local elf connector, The 'dt _ runpath' and 'dt _ rpath' operators in the shared library will be searched by the shared library.
If 'dt _ runpath' exists, 'dt _ rpath' will be ignored.
Development Network ---- the most professional electronic forum, the most professional electronic engineer blog Q
L! EO '0yc
^

5sd8scr2 ^ y0
7.
Default directory, such as '/lib' and'/usr/lib '.
~ 6t1tl5s, w0

: _ WC l �p $ b0e $ e $ Y: I0
8. For local connectors on the elf system,
If the file '/etc/lD. So. conf' exists, some directories in the file will be searched.
Sub-top development network ---- the most professional electronic forum, the most professional electronic engineer blog 4 V] * g/1y6n9gg; D/+ P

Top electronic development network in China ---- the most professional electronic forum, the most professional electronic engineer blog +/& [Lou
I}

Slave
The above shows that when local compilation is performed using the local tool chain, as long as the inventory is in a certain position, GCC can always find the desired shared library through the above policy. However, in cross-compilation, the above eight policies can be
There are only two in use:-rpath-link and-rpath. These two options have the highest priority among the above eight policies. If you specify these two options
To, the linker will first search for the desired shared library in the path specified by the two options. The above description shows that the path specified by-rpath will be written to the executable file;-rpath-
Link does not. We certainly do not want to write the path information used in cross-compilation into the final executable file, so we choose to use option-rpath-link.
El) x �o [Ia '0

/8A "U-F * pr6a0
 
GCC option "-wl, -- rpath-Link
-Wl, Dir "will pass the-rpath-link option and path information to the linker. Return to the example above. If no libb. So is displayed in the command line, but GCC specifies "-
WL, -- rpath-Link
-Wl, Dir ", when the linker cannot find libb. So, it first goes to the path specified by-rpath-link to find the dependent library. Here we use an example of the compilation command
Is a tool chain that uses the Unicore platform. China's top electronic development network-the most professional electronic forum, the most professional
E-engineer blog g W + tdq

Da. S + beh0
$
Unicore32-linux-gcc-O myprog/usr/lib/LIBA. So/top electronic development network in China ---- the most professional electronic forum, the most professional electronic engineer blog % H + _ '; AK

G (WO] 'M' V0
-Wl, -- rpath-Link
-Wl,/home/unity_float/install/usr/lib
9A # @
N0w �y' A0

, Omlyk {xn 'w0
This
The compiler first searches for libb. So under "/home/unity_float/install/usr/lib ".
"@ WM 'G | K! ^! AA] 0i-o0
China's top electronic development network-the most professional electronic forum, the most professional electronic engineer blog! X3qfab # l
H9j: V

 
How does libtool set the option "-wl, -- rpath-link "?
-Wl, Dir "passed to GCC? In libtool, there is a variable "hardcode_libdir_flag_spec", which is originally passed "-rpath"
Option, but we can modify it, add the path we need, and pass it to the unicore32-linux-gcc. Top electronic development network in China ---- the most professional electronic forum, the most professional electronic engineer blog/c | E6 @? Vhaai

5 ~ ? @) F! G & Y? Vn0

The original definition of "hardcode_libdir_flag_spec" is as follows: China Electronics top-level open
Hair network ---- the most professional electronic forum, the most professional electronic engineer blog WL _/P/} $ I ^! Z

5? 0 ~ V) Q. yl0
Hardcode_libdir_flag_spec = "/$ {WL} -- rpath
/$ {WL}/$ libdir"
U3tyd �by) V # pk0
Top electronic development network in China ---- the most professional electronic forum, the most professional electronic engineer blog e9c * [) mnw

Me
The modified definition is as follows: China's top electronic development network-the most professional electronic forum, the most professional electronic engineering teacher Bo
Customer h9qph5ww & B/Z-Ka

FY] nm0
Hardcode_libdir_flag_spec = "/$ {WL}-rpath-Link
/$ {WL}/$ libdir/
"L
V1q;}. wx + k
_) Lqa )? 0
China's top electronic development network-the most professional electronic forum, the most specialized
E-engineer blog C8 ~ 1 ~ [�Q'] 0 hlni

-Wl, -- rpath-Link
-Wl,/home/unity_float/install/usr/lib/China Telecom
Sub-top development network ---- the most professional electronic forum, the most professional electronic engineer blog $ Y & V "d6k) w2f
^ + ~ U

MF; k5_e8/0000f0
-Wl, -- rpath-Link
-Wl,/home/unity_float/install/usr/x11r6/lib"
V! E5cprkh0
Top electronic development network in China ----
Blog B "K: B3m & Y: ig3l

In this way, when libtool
In "-- mode = link" mode, the option "-wl, -- rpath-link-wl, Dir" is passed to the GCC compiler.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.