Static Libraries… What are we talking about??

HOW CAN WE CREATE A STATIC LIBRARY?

  • First of all we need a .C file where our function is contained.
  • Our second step should be, create a header which contains our function.
  • We must compile our .C file, to make it a .O file
  • At last we need to create the static libary with our function inside it. So… how can we do it??

ar -rc name_of_libary.a our_function.o

HOW TO USE THEM?

gcc my_program.c -L. -lname_of_library -o my_program

  • First of all -L says “look in directory for library files” if we add a dot it means the current directory.
  • -l says “link with this library file followed the name of our library, ommiting the .a prefix of it.
  • And at last -o option followed by teh program we want to compile.

--

--

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