DEV Community

Trinity
Trinity

Posted on

How to create static library in c

#c

Summarizing https://www.youtube.com/watch?v=t5TfYRRHG04&t=84s

  1. Create a source file (.c) and header file (.h)
  2. Write function in source file and prototype in header file
  3. Create lib and include directory
  4. gcc -c <source>.c
  5. ar cr lib<name>.a <source>.o. Defines library name output and source object file
  6. ar t lib<name>.a to find out what function names are included
  7. move the lib<name>.a file to lib folder
  8. gcc <source>.c -l<name> -L <library_folder_name> -o <output_file_name> -I <include_folder_name>. If you created lib and include directory that's where they should go under librar_folder_name and include_folder_name.

Top comments (0)