Learn C Programming

Lesson 5 of 8 · The Preprocessor, Headers and Multi File Builds

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'.

Pro lesson

This one goes deeper

It is included with this track and with Learn Pro. Every question on the Skill Test can be answered from the free lessons, so this is depth and never a gate on the certificate.

What is inside Static and Shared Libraries, and Linking Someone Else's Code

  1. What a library is
  2. A static library: object files in one archive
  3. What -l and -L tell the linker
  4. A library goes after the files that need it
  5. A shared library: loaded when the program starts
  6. Why the Playground links -lm
  7. Linking someone else's code: SQLite
  8. Read the licence before you link