I'm trying to add a sanity check at the link stage. Specifically, I have programs that are statically linking libraries. Some programs are limited to the set of libraries allowed to be linked while others are not. So say for example I have two programs respectively from food.c
and fruits.c
, and I have two libraries (for which I have source) apple.a
and broccoli.a
. There is no dependency between apple.a
and broccoli.a
.
Is there a way I can modify my source and the libraries' source such that the linker will allow me to link both apple.a
and broccoli.a
into food.c
, and will allow me to link apple.a
into fruits.c
, but will produce a linker error when I try to load apple.a
and broccoli.a
(or just broccoli.a
) into fruits.c
? Assume that my source does not #include
any headers in the libraries they link, as they are linked in by mistake, are left over from deleted code, function prototypes are manually declared, and so on.
What would be nice is if I could somehow tag these libraries in such a way that my program can reject a particular tag.
The specific compiler I'm using does not implement #pragma poison
, which was really the only helpful tool I've found in my search. My hunch tells me there might be something clever I can do with weak symbols, but I'm not exactly sure what or how.
I also don't believe using #define
will help me, as my understanding is that would only prevent me from #include
ing specific files, but if I'm mistaken in that, then that could also be a fine solution.