2
votes

How do I create a custom library in GNU? What I mean is:

When we use #include < stdio.h> and printf

we can compile it with gcc main.c

Now I create my custom headers and .a/.so library files, I know I can set the environment variable C_INCLUDE_PATH and include my header files with #include<> instead of #include"". However, I still have to compile it with

gcc main.c -o program -L/whatever/ -lwahtever

(with set environment variable if using .so)

Is it possible to make it behave like #include< stdio.h> where I don't need to include the paths with corresponding command line arguments?

1
Is there a way of removing '-l' like standard libraries? - Thenewstockton

1 Answers

0
votes

You actually don't need -L/whatever/, just -lwhatever. The first option supplies the path to your library, but you have already taken care of that with the #include and modifying C_INCLUDE_PATH. The second option tells the linker which library to link your executable with. An example of this is when using functions from the C math library, you #include <math.h>, but to compile, you still need the linker option -lmath. So to answer your question, no. You can remove the first option, but you must leave the second.