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.
Asked
Active
Viewed 182 times
2
-
Is this question about adding shared libraries to the linker, or about using functions from shared libraries in your code? – arc_lupus Nov 19 '14 at 13:41
-
Is there special reason to make library? Why not simply include the source in each program? – i486 Nov 19 '14 at 13:44
-
About both of them :) – ondrousn Nov 19 '14 at 13:44
2 Answers
1
#include
the header file containing the declaration of the function(s) you want to use in your main file.link with your shared library using
-L/path/to/libraries abc.c -l<yourLIb>
. [Assuming your libary name islib<yourLIb>.so
]
Note: You can find some good reads here.

Sourav Ghosh
- 133,132
- 16
- 183
- 261
-
Everything is in the same folder, so do I use -L. "main fle name" -l
??? – ondrousn Nov 19 '14 at 14:00 -
0
Define function prototypes in header .h file(s). And add library name to linker parameters.

i486
- 6,491
- 4
- 24
- 41