Including header files in a static library

Since every time we link to a static library we also need to include the header files, I'm wondering if it is possible to archive into a static library when it is created, these chapters?

Let's say I have two object files foo1.o

and foo2.o

, generated by

gcc foo1.c -I foo1.h -c -o foo1.o
gcc foo2.c -I foo2.h -c -o foo2.o

      

The Gcc tutorials tell us what we can generate libfoo.a

with

ar libfoo.a foo1.o foo2.o 

      

This should sound silly, but can these header files be put in libfoo.a when archiving? This way, when attached to libfoo.a

people, you no longer have to spend hours to find and turn on foo1.h

and foo2.h

, therefore, there seems to be some benefits in doing so, right?

Thanks for your ideas.

+3


source to share


2 answers


The header should first compile your source, not link it. You don't need a header to link your objects to static libraries.

Secondly, no, there is no standard or common way to create an archive with both a library and a header. There is probably no way to do this with regular C compilers.

You can declare library prototypes inside your source and ignore the header. But that would be unsafe as there would be no guarantee that both the library and the source are compiled with compatible prototypes.

Following the Paul Griffiths

comments. If you just don't want to include the path for every library, you must install those headers and those libraries and set the path in your environment.



Example:

export C_INCLUDE_PATH=$HOME/install/include
export LIBRARY_PATH=$HOME/install/lib

      

You have to export this every time you open a new shell, or you can define it in .bashrc

+1


source


You can compile whatever you want into a static library, but similarly, you cannot call functions from the outside (for example, by binding), because if you want to do this, you will always need their prototypes



+1


source







All Articles