Building foo
(executable or library) from the C++ source code involves three steps: preprocessing, compilation and linking.
If foo
depends on a shared library bar
, whenever we execute foo
, we must be able to locate and load bar
too.
In Linux: ld.so
scan different directories where to find libbar.so
in the following order:
RPATH
. A list of directories which is linked into the executable, supported on most UNIX systems. It is ignored if RUNPATH
is present.LD_LIBRARY_PATH
. Environment variable which holds a list of directories.RUNPATH
. Same as RPATH
, but searched after LD_LIBRARY_PATH
and not universally supported./etc/ld.so.conf
. Configuration file for ld.so
which lists additional library directories.In macOS: dyld
locates each library using the full path to each dylib, so foo
must contain the install name for bar
. These dependencies can be seen using otool -L foo
.
DYLD_LIBRARY_PATH
.RPATH
. For relocatable libraries, these directories can contain @loader_path
and @executable_path
(are replaced by the location of foo
) and @rpath
(substituted with the RPATHs in foo
)./lib
, /usr/lib
).DYLD_FALLBACK_LIBRARY_PATH
.Use gnu nm to examine the object (*.o, library, etc.):
nm libgin.a
Output:
Being inexpert in LLDB, this is the workflow I follow to debug my R packages after they crash.
bt
to find out where are we in the code.frame select 14
.po VARIABLENAME
.