Description of a library

How do static libraries work?

Creating a library

  • ar is the command to create a library
  • The ´c´ flag tells ar to create the library if it doesn't already exist.
  • The ´r´ flag tells it to replace older object files in the library, with the new object files.
  • The text lib before the name of the library (test) is always use to let the program know that “test” is the name of the library.
  • file1.o and file2.o are the object files copied inside the library.
  • -I <include directory>
  • -L <library>
  • Test is the name of the library.
  • The ´-I´ option is used to specify any non-standard include directories
  • The ´-L´ option is used to specify any non-standard library directories

Using a Static Library

  • cc main.o -L. — ltest -o prog

Sources

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store