Search code examples
cgccmakefilesharedlibs

C - Using shared library


I have made makefile which is creating shared library of two C code files (I used gcc). Makefile is also creating runnable main C file. Now I need to know how to tell main C file to use my shared library - because I need to use functions which are already contained in code files in shared library. Thanks for the help.


Solution

    1. #include the header file containing the declaration of the function(s) you want to use in your main file.

    2. link with your shared library using -L/path/to/libraries abc.c -l<yourLIb>. [Assuming your libary name is lib<yourLIb>.so]

    Note: You can find some good reads here.