Shared Libraries (Preview)

“Normal” Libraries

  • STATIC

    • Simple bag of objects

    • Linker copies objects out

  • SHARED

  • MODULE

    • No SONAME, no version symlinks

Building Shared Libraries

  • In the CMakeLists.txt, using SHARED tag

    ADD_LIBRARY(hello SHARED hello.c hello-name.c)
    
  • From the commandline, setting BUILD_SHARED_LIBS to ON

    $ cmake -DBUILD_SHARED_LIBS=ON ...
    

More About Loading

  • Program interpreter ⟶ hash bang in scripts

  • /etc/ld.so.conf

  • Library SONAME and NEEDED tags ⟶ 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