Shared Libraries (Preview)#
“Normal” Libraries#
STATICSimple bag of objects
Linker copies objects out
SHAREDLoaded at runtime
⟶ Loader (usually
/lib64/ld-linux-x86-64.so.2)
MODULENo
SONAME, no version symlinks
Building Shared Libraries#
In the
CMakeLists.txt, usingSHAREDtagADD_LIBRARY(hello SHARED hello.c hello-name.c)From the commandline, setting
BUILD_SHARED_LIBStoON$ cmake -DBUILD_SHARED_LIBS=ON ...
More About Loading#
Program interpreter ⟶ hash bang in scripts
/etc/ld.so.confLibrary
SONAMEandNEEDEDtags ⟶ look in/usr/lib64/$ rpm -qf /usr/lib64/libboost_regex.so.1.76.0 $ sudo dnf install boost-devel
A-ha: development versions
$ ls -l /usr/lib64/libboost_regex* lrwxrwxrwx. 1 root root 24 Jul 14 2022 /usr/lib64/libboost_regex.so -> libboost_regex.so.1.76.0 -rwxr-xr-x. 1 root root 289264 Jul 14 2022 /usr/lib64/libboost_regex.so.1.76.0
Temporarily add
SET_PROPERTY(TARGET hello PROPERTY VERSION "1")``and modify to
PROJECT(Demo VERSION "1.0.0") SET_PROPERTY(TARGET hello PROPERTY VERSION ${PROJECT_VERSION})
Discuss ABI versions ⟶ rarely project versions can be used as ABI versions
⟶ can of worms: installation/deployment