c++ - gcc/ld: what is to -Wl,-rpath in dynamic linking what -l is to -L in static linking? -
with /my/dir/path/foo.a , /my/dir/path/bar.a:
to statically link using gcc/g++, 1 uses -l
specify directory containing static libraries , -l
specify name of library. in case 1 write gcc -l/my/dir/path -lfoo -lbar ...
.
with /my/dir/path/foo.so , /my/dir/path/bar.so:
to dynamically link using gcc/g++, 1 uses -wl,-rpath,/my/dir/path
. how names of libraries specified? command gcc -l/my/dir/path -wl,-rpath,/my/dir/path -lfoo -lbar ...
correct? or should gcc -l/my/dir/path -wl,-rpath,/my/dir/path -wl,-lfoo -wl,-lbar ...
? in other words, library names need passed on linker through -wl,-l
?
the -l
argument works both static , shared libraries expects filename of specified library in specific format. namely, -lfoo
tells linker file named libfoo.a
or libfoo.so
. if want links against library filename don't have 'lib' prefix (i. e. foo.so
), can use semicolon , specify filename: -l:foo.so
.
so, dynamically link against /my/dir/path/foo.so
, /my/dir/path/bar.so
need issue following command:
g++ -l/my/dir/path/ -l:foo.so -l:bar.so
as -rpath
, has -rpath=<path>
format, in order pass linked need issue following:
g++ -l/my/dir/path/ -wl,-rpath=/my/dir/path/ -l:foo.so -l:bar.so
Comments
Post a Comment