Reputation: 76256
I have a pile of files, that are compiled to a library that is linked to various projects, but most of the projects only need relatively small part of it. So I need to split it to layers.
To do that properly I would like to check that the lower layers don't depend on anything in the higher ones. On Linux I'd simply make the libraries shared and pass -Wl,--no-undefined
to the link. But I need to do it on Windows where dynamic libraries need explicit exports and the sources are not prepared for that.
I can also prepare a unit test for each layer and have the undefined symbols pop up during linking of that. However I only have unit tests for small subset of the classes and even if I add them, they still won't catch if something is added but not tested.
So is there some other way to check that a static library does not need any symbols except from specified set of other libraries? I can use either Visual C++ 9.0 (2008) or MinGW.
Upvotes: 4
Views: 355
Reputation: 1915
Hmm, I can share with you something I came up with for force linking specific to visual studio. It's not exactly scanning to make sure all symbols are linked, though this works for myself when forcing registration globals to link (that aren't actually referenced anywhere in code). To be placed in a header:
#define DECLARE_OBJ( TYPE, INSTANCE_NAME ) \
extern "C" TYPE INSTANCE_NAME; \
__pragma( comment ( linker, "/INCLUDE:_" __STRINGIZE( INSTANCE_NAME ) ) )
This does issue of a warning about a space between the two compile-time strings. iirc I pragma'd the warning away as it was completely useless. Hope this helps.
Upvotes: 1