The C Static Libraries

Why do I need to use C Static Libariaires?

How to create them and how they work?

$ gcc -c *.c
$ ar rc libmylib.a *.o
[pierre@ubuntu 0x09-static_libraries]$ ar -t libmylib.a
0-isupper.o
0-memset.o
[...]
9-strcpy.o
_putchar.o
[pierre@ubuntu 0x09-static_libraries]$ nm libmylib.a 

0-isupper.o:
0000000000000000 T _isupper

0-memset.o:
0000000000000000 T _memset

[...]

9-strcpy.o:
0000000000000000 T _strcpy

_putchar.o:
0000000000000000 T _putchar
U write
$ ranlib libmylib.a

How to use them?

$ gcc main.c -L. -lmylib
  • -l<library name>, without the lib prefix and the .aextension
  • -L : path to the library

--

--

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