Let's say, in my C executable project, I use a C library to which I have source access - in fact, the .c files of the library get built as part of the build process for my C executable.
Then, let's say in some of the library .c files, let's say exotic.c
, there is something like:
static struct exotic_type all_exotic_array[NUM_EXOTIC_ITEMS][8];
... which the author of the library believes should remain hidden (ergo static
) - but which, it turns out, I need a reference to in my code; therefore I'd like to make this variable's symbol publicly accessible.
So, in principle I could just erase the static
keyword there and recompile - and I'd get the all_exotic_array
as global. However, let's say I also do not want to change the source code of the library.
So in this context, I can intervene in the Makefile, when the individual library .c files get compiled. So:
- Is there a compilation switch, with which I could tell the compiler
gcc
(or linkerld
?), while compilingexotic.c
, something like: "please ignore thestatic
storage class specifier of the symbolall_exotic_array
, and make it available globally"? - If not - is there any other action I could take (maybe after compilation of
exotic.c
but before linking my executable), to make the symbolall_exotic_array
globally available?
I have seen
- Access of static variable from one file to another file
- Renaming symbols at compile time without changing the code in a cross platform way
- Access a global static variable from a .so file without modifying library
- Keep all exported symbols when creating a shared library from a static library
... which hint that there may be a possibility to do what I want, however I couldn't find exactly what to do in my use case.