Student writes all the code for an executable program. The only other code used is in standard libraries, which is automatically taken care of for you.
-O1
, -O2
, -O3
, where higher is faster code but which takes longer to compile and potentially larger object sizenm
displays the name list (symbol table) of object codeT
is external text (code) sectionU
is external undefined (does not exist in this file)incr
increment.cpp
code in another executable, it would be duplicatedincr
) wants to use, e.g., suppose a decrement.cpplib
ar
command (man ar) to create and view static libraries-L
option tells the compiler where the static library files are. In this case, the current directory-l
option tells the compiler to link in the object code from the static library, where the prefix lib of the library name libincrement.a is assumedincr
-fPIC
-shared
makes it a shared library-L
option tells the compiler where the shared library files are. In this case, the current directory.-l
option tells the compiler to link in the object code from the shared library, where the prefix lib of the library name libincrement.so is assumedincrement()
is not in the executable incr
. However, the executable incr
knows how to call the functionincr
, cannot find the shared library and needs the object code for increment()
ldd
command on Linux and the otool -L
command on macOSsudo
in front of the ldd
commandLD_LIBRARY_PATH
is a temporary way of doing this/usr/lib
or /usr/local/lib
sudo
for the cp
command due to the destination locationldconfig
(man ldconfig) updates this cacheldd
command now shows-Wl
forwards options to the linker-soname,libincrement.so.1
sets the soname field of the shared library to libincrement.so.1ldconfig
generates the appropriate symbolic link