C - Using shared library

191 views Asked by At

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.

2

There are 2 answers

2
Sourav Ghosh On BEST ANSWER
  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.

0
i486 On

Define function prototypes in header .h file(s). And add library name to linker parameters.