Ramesh Kamath Ramesh Kamath - 2 years ago 141
Linux Question

Adding a custom library to c programs

I am using Ubuntu Linux
I have made a custom static library Mylib.a, I can include it to only those c files which are in the same directory as the static library.

I want to make it a general library so that I can include the library file to any c file I want irrespective of its location

Answer Source

You can copy that .a file (or better .so file) to a standard location such as /usr/lib.

If you compile from the command line, you also need to specify the library name (even if it's already in /usr/lib), the same way when you specify standard library like -lpthread.

You can also specify the library path and library name in makefile

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download