Module 15 · The Preprocessor, Headers and Multi File Builds
Static and Shared Libraries, and Linking Someone Else's Code
ProReading
In Module 6 lesson 6, Kenji used sqrt(n) as a loop's limit. The brain teaser asked you to compare the Playground's command line with a bare gcc. The difference is three characters at the end, -lm. On Linux, a build without them stops with undefined reference to `sqrt'.
Checking what this lesson needs for you…
What is inside Static and Shared Libraries, and Linking Someone Else's Code
- What a library is
- A static library: object files in one archive
- What -l and -L tell the linker
- A library goes after the files that need it
- A shared library: loaded when the program starts
- Why the Playground links -lm
- Linking someone else's code: SQLite
- Read the licence before you link