lundi 10 octobre 2016

Preventing linkers (esp. XCode) from removing unreferenced functions

I have a set of Catch unit tests for a static library, which are currently built into an executable by CMake. This is causing problems for iOS users of the library, as CMake apparently has problems with the latest XCode.

I would like to move the unit tests into a separate static library to be built by CMake; the library could then be used with whatever build system was most suitable for the platform.

Unfortunately, Catch, Google Test and most other C++ testing frameworks register tests by creating static objects. Modern linkers determine that the constructors for these objects are not being called from outside the library and so do not link them into the final executable. This prevents the tests from being executed.

I would be grateful for pointers to gcc, clang and (especially) XCode linker settings to disable the stripping of apparently unused code. I'm aware that this may make the executables a lot bigger -- that's an acceptable price to pay, as the tests executable will not need to be distributed.

Aucun commentaire:

Enregistrer un commentaire