I. Link and link options for dynamic libraries-l,-rpath-link,-rpath
(1). The modern connector separates the link-time path (link-time path) and the run-time path (run-time path) when processing a dynamic library.
The user can specify the path to the library when connected by-l
Specifying the path of the program runtime library through-R (or-rpath) greatly improves the flexibility of the library application.
Link-time Path |
-l Specifies the path to the library when connecting |
-L |
Run-time Path |
-R (or-rpath) specifies the path of the program run-time Library |
-rpath-link
|
-rpath |
For example, when we do the embedded porting #arm-linux-gcc $ (CFLAGS) –o target–l/work/lib/zlib/-llibz-1.2.3 (Work/lib/zlib is a cross-compiled zlib library),
After the target is compiled we simply copy the Zlib library to the system default path of the development Board. Or, the lookup path is specified by-rpath (or-R), Ld_library_path.
The linker LD option has-l,-rpath and-rpath-link, looked at the next man ld, roughly this meaning:
- -L: "link", the directory to be found, that is, all the-lfoo options in the library, will be first from the directory specified by-L to find, and then the default place.
the-l option at compile time does not affect the environment variable ld_library_path, - L only specifies the path of the library when the program compiles the connection, and does not affect the path of the library when the program executes .
The system will still go to the default path to find the library required by the program, if not found, or will error, similar to cannot open shared object file.
- -rpath-link: This is also used for "link" time, such as you display the specified need foo.so, but foo.so itself is need to bar.so, the latter you do not specify, but foo.so reference to it,
At this time, we will first look for the path from the-rpath-link.
- -rpath: "Run" the time, go to find the directory. When running, to find the. So file, you will find it from the location specified in this option.
For cross-compilation, the cross-compiling linker needs to have the –WITH-SYSROOT option configured to work.
That is, the path specified by-rpath is recorded in the generated executable program and is used by the runtime to find the dynamic library that needs to be loaded. -rpath-link is only used for link-time lookups.
(2). When using the LD link option in gcc, prefix-wl (the letter L, not 1) is required before the option.
if the linker is being invoked indirectly,via a compiler driver (GCC) then all the linker command Li NE options should be prefixed by-wl,
(or whatever is appropriate for the particular compiler driver) like this : <!--lang:shell--> GCC -wl,--start-group foo.o bar.o-wl,--end-group this is Important, because otherwise the compiler driver program may silently drop the linker options, resulting in a bad link.
The -Wl,xxx
option for gcc passes a comma-separated list of tokens as a space-separated list of arguments to the linker. So
gcc -Wl,aaa,bbb,ccc
Eventually becomes a linker call
ld aaa bbb ccc
In the your case, your want to say " ld -rpath .
", so-pass this to the -Wl,-rpath,.
gcc as alternatively, you can specify repeat instances of -Wl
:
gcc -Wl,aaa, -Wl,bbb -Wl,ccc
Or, in the Your case,
-Wl,-rpath -Wl,
.
(3). Direct man LD View detailed documentation
Linux toolchain (ii)---Linker (1) Link Options-l-rpath-rpath-link