Building an executable
foo (executable or library) from the C++ source code involves three steps: preprocessing, compilation and linking.
foo depends on a shared library
bar, whenever we execute
foo, we must be able to locate and load
ld.soscan different directories where to find
libbar.soin the following order:
RPATH. A list of directories which is linked into the executable, supported on most UNIX systems. It is ignored if
LD_LIBRARY_PATH. Environment variable which holds a list of directories.
RUNPATH. Same as
RPATH, but searched after
LD_LIBRARY_PATHand not universally supported.
/etc/ld.so.conf. Configuration file for
ld.sowhich lists additional library directories.
- Builtin directories (/lib, /usr/lib).
dyldlocates each library using the full path to each dylib, so
foomust contain the install name for
bar. These dependencies can be seen using
otool -L foo.
RPATH. For relocatable libraries, these directories can contain
@executable_path(are replaced by the location of
@rpath(substituted with the RPATHs in
- Builtin directories (
Get symbols of an object file
Use gnu nm to examine the object (*.o, library, etc.):
- Symbol value
- Symbol type. Uppercase for global, lowercase for local. The most frequent are
- t/T: symbol in the text (code) section.
- U: symbol undefined.
A workflow for LLDB
Being inexpert in LLDB, this is the workflow I follow to debug my R packages after they crash.
- Run the command that causes the crash, and stop there.
- Do a backtrace with
btto find out where are we in the code.
- Go to the frame in the stack that you want to examine. For example, for frame #14,
frame select 14.
- Examine variables with