Alternatively, you could explicitly reference all the symbols of interest from the main executable. That gives you just what you need, still allowing the linker to strip out the unreferenced things you don't need.
Another benefit of this approach is that you'll end up with some code that shows you the list of things you are actually pulling in to your executable. HTH, David On Sat, Jan 24, 2009 at 12:01 PM, Timenkov Yuri <[email protected]> wrote: > This problem may occur with gcc because of static library linking policy. > If you have a symbol in static library which is not referenced from main > executable it will not be linked in. (For example, if you use static classes > to register something to factories). To solve this issue, you should either > link whole static lib (with --whole-archive linker option) or explicitly > mark the symbol of interest as undefined (with --undefined option). I > usually use first approach, because decorating C++ name is not trivial task. > > > On Sat, Jan 24, 2009 at 6:00 PM, Aleix Pol <[email protected]> wrote: > >> hi list, >> I'm having a little problem involving c++ static initializations using >> static libraries libraries. The problem is that if I link this code to the >> executable as a static library the code is never run, but if it is a SHARED >> library it is, but I need it to be static (if possible). >> >> The code looks like this: >> struct AClass { >> static Object* registration() {...} >> static int Aregistered=something("A", AClass::registration); >> }; >> >> Any hint on what should I do so that it is called as i expect? >> >> Thanks, >> aleix >> >> _______________________________________________ >> CMake mailing list >> [email protected] >> http://www.cmake.org/mailman/listinfo/cmake >> > > > _______________________________________________ > CMake mailing list > [email protected] > http://www.cmake.org/mailman/listinfo/cmake >
_______________________________________________ CMake mailing list [email protected] http://www.cmake.org/mailman/listinfo/cmake
