# shared libraries ## panel 1 most programs on Linux use a bunch of libraries. some popular libraries: * openssl (for SSL!) * sqlite (embedded db!) * libpcre (regular expressions!) * zlib (gzip!) * libstdc++ (C++ standard library!) ## panel 2 There are 2 ways to use any library: 1) Link it into your binary (image: box containing 3 things, code, zlib, sqlite) (arrow pointing up): big binary with lots of things! 2) Use separate shared libraries (image: 3 separate boxes: code, zlib, sqlite) (arrow): all different files ## panel 3 Programs like this (image: box containing 3 things, code, zlib, sqlite) are called "statically linked" and programs like this (image: 3 separate boxes: code, zlib, sqlite) are called "dynamically linked" ## panel 4 person 1: "how can I tell what shared libraries a program is using?" person 2: "ldd!" ``` ldd /usr/bin/curl libz.so.1 => /lib/x86_64... libresolv.so.2 =>... libc.so.6 => ``` +34 more :) ## panel 5 person 1: "I got a "library not found" error when running my binary?!" person 2: "If you know where the library is, try setting the LD_LIBRARY_PATH environment variable" dynamic linker (thinking): LD_LIBRARY_PATH tells me where to look ## panel 6 where the dynamic linker looks 1. DT_RPATH in your executable 2. LD_LIBRARY_PATH 3. DT_RUNPATH in executable 4. /etc/ld.so.cache (run ldconfig -p to see contents) 5. /lib, /usr/lib
https://cdn.masto.host/socialjvnsca/media_attachments/files/109/728/590/326/012/337/original/9593cb2238b138bc.png