- Create two folders, name the first folder 'utils' and the second folder 'headers'
- Write your functions in a
.c
file and put it in the utils folder. - Create a
.h
file with the same name as the.c
file that contains the functions. Put the header files in the headers folder. The.h
file should contains following code. - Open terminal and go to the utils folder and compile the .c files using this command
gcc -c *.c
- Build the library by putting all the .o files in an archive using this command
ar -cvq yourlibraryname.a *.o
library name starts with lib, and don't froget the .a extension at the end - Now you can use the library in your program by adding a file header
#include "headers/yourLibraryName.h"
- Compile your program by providing the library name
gcc -o programName programSourceCode.c utils/libraryName.a
- If youre using C-Lion IDE, you can simply add your
.c
and.h
paths to the CMakeList.txt like this:
10 October 2017
Creating own library in C
To create your own library in C please follow this steps: