c++ - G++ 4.9 - function at module scope not being called? -


i using module-level function call register factory function registry class:

static controller * ctor( device * device, const char * ) { return new nullcontroller(device); } static int s_id = deviceregistry::registercontrollerclass( "null", ctor );  //------------------------------------------------------------------------------  nullcontroller::nullcontroller( device * device ) : controller( device, "null", s_id ) { } 

where eg::dev::deviceregistry::registercontrollerclass() free function in namespaces eg , dev. works under visual studio, code not appear called when running on gcc/linux - if breakpoint registercontrollerclass(), not invoked. in case compiler optimizing out s_id field, used construct base class. i'm sure it's not that. what's wrong code?

linker trying clever , removing code thought not called, invoked indirectly.

adding command line options in netbeans linker options dialog around library

-wl,--whole-archive lib -wl,--no-whole-archive ...

solves problem. yuk.


Comments