Other Factory Notes

other notes:

The following works:

extern "C" void Af(void);
void (*Af_fp)(void) = &Af;
For those that want a self-contained preprocessor macro to encapsulate this:

#if defined(_WIN32)
# if defined(_WIN64)
#  define FORCE_UNDEFINED_SYMBOL(x) __pragma(comment (linker, "/export:" #x))
# else
#  define FORCE_UNDEFINED_SYMBOL(x) __pragma(comment (linker, "/export:_" #x))
# endif
# define FORCE_UNDEFINED_SYMBOL(x) extern "C" void x(void); void (*__ ## x ## _fp)(void)=&x;

Which is used thusly:

MSVC #pragma comment(linker, "/include:__mySymbol")

gcc -u symbol

There is a better way to write that FORCE_UNDEFINED_SYMBOL macro. Just cast that function pointer to a void*. Then it works with any function - or data for that matter. Also, why bother with MSVC pragmas when the gcc part of your macro will work for MSVC as well. So my simplified version would be:
#define FORCE_UNDEFINED_SYMBOL(x) void* __ ## x ## _fp =(void*)&x;

Which is used thusly:

But it must be used in the program that includes the library that is having its symbols stripped.

I believe (to be tested) that this export or extern might only work if these are in the main program ... which doesn't solve the problem for Geant4 (the point of the factory is that user code shouldn't need to explicitly name physics processes or lists they want to use).

That said, other suggested "solutions" revolve around

__pragma(comment (linker, "/include:_mySymbolName"))