Student writes all the code for an executable program. The only other code used is from standard libraries, which are automatically handled for you.
-O1, -O2, -O3, where higher is faster executable code but takes longer to compile and potentially has a larger object sizenm displays the name list (symbol table) of the object codeT is the external text (code) sectionU is externally undefined (does not exist in this file)incrincrement.cpp code in another executable, it would be duplicatedincr) wants to use, e.g., suppose a decrement.cpplibar 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 assumedincrar.a extensionlibc Standard C library (glibc on Linux)libgcc GCC runtime support librarylibstdc++ C++ standard library-l option/lib, /usr/lib, /lib64, /usr/lib64/usr/local/lib. Some of the RPM distributions do, e.g., OpenSUSE, and some do not, e.g., Fedora, CentOS| Platform | Typical Compiler | Extension |
|---|---|---|
| Linux | gcc | .a |
| macOS | clang | .a |
| Windows | MSVC | .lib |
-shared makes it a shared library-fPIC-fPIC on, and store in both static and shared libraries, or build twice, one with -fPIC on for the shared library, and one with -fPIC not on for the static 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/libsudo for the cp command due to the destination locationldconfig (man ldconfig) updates this cacheldd command now showsbrew uses /opt/homebrew/bin for Apple Silicon Macs and /opt/homebrew/lib for Intel Macs (or in Rosetta2)-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