Static library "interface"

Is there a way to tell the compiler (gcc / mingw32) when creating an object file ( lib*.o ) to expose only certain functions from a .c file?
The reason I want to do this is because I am statically linking to a 100,000+ linear library (SQLite), but I only use a few select features. I hope that if I can only tell the compiler to expose these functions, it optimizes the entire code of functions that are never needed for the few that I have chosen, thereby drastically reducing the size of the library.

+4
source share
2 answers

I found several possible solutions:

This is what I asked. This is the gcc equivalent of Windows' dllexpoort :

I also discovered time channel code generation. This allows the linker to see which parts of the code are actually used and get rid of the rest. Using this with strip and -fwhole-program gave me significantly better results.

Note. This flag only makes sense if you are not compiling the entire program in one gcc call, which I did (by creating the sqlite.o file and then statically linking it to).

The third option that I have found but not yet explored is mentioned here:

+1
source

Perhaps this is the work of linkers, not compilers. When linking this as a program (.exe), the linker will only take care of importing the corresponding characters, and when linking the DLL, the __dllexport mechanism is probably what you are looking for, or some ld flags can help you (LD person).

0
source

All Articles