How do I determine the Ubuntu Linux Library Path? That is, how does the linker know where to got to grab the object files when linking my program?
The file paths can be set explicitly when linking using the -L
parameter, as well as the environment variable LD_LIBRARY_PATH
.
There are also some paths hard-coded into the linker, using the -L
param. You can see these with the command:
gcc -Xlinker -v
If it's not a standard path (/lib
, /usr/lib
), you can specify the location with the compiler flag. For g++
, it's -L/some/path/lib
. If you use autotools, you can just configure with LDFLAGS=-L/some/path/lib
if you need a specific path. If configure has been properly designed for the project, it should have a --with-some-library=PATH
option, where you can also specify a path for that library only.
Look at /etc/ld.so.conf
and the files in the /etc/ld.so.conf.d/
directory -- that's where it is set.
When linking, you need to specify the -L flag to indicate where the library is located. At runtime, the dynamic linker uses the paths given in "/etc/ld.so.conf", "/etc/ld.so.conf.d/*" and the value of LD_LIBRARY_PATH.