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.<br>
<br><br><div class="gmail_quote">On Sat, Jan 24, 2009 at 6:00 PM, Aleix Pol <span dir="ltr"><<a href="mailto:aleixpol@kde.org">aleixpol@kde.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
hi list,<br>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).<br>
<br>The code looks like this:<br>struct AClass {<br> static Object* registration() {...}<br> static int Aregistered=something("A", AClass::registration);<br>};<br><br>Any hint on what should I do so that it is called as i expect?<br>
<br>Thanks,<br><font color="#888888">aleix<br>
</font><br>_______________________________________________<br>
CMake mailing list<br>
<a href="mailto:CMake@cmake.org">CMake@cmake.org</a><br>
<a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br></blockquote></div><br>