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.<br><br>
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.<br><br><br>HTH,<br>David<br><br><br><div class="gmail_quote">On Sat, Jan 24, 2009 at 12:01 PM, Timenkov Yuri <span dir="ltr"><<a href="mailto:ytimenkov@gmail.com">ytimenkov@gmail.com</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;">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"><div><div></div><div class="Wj3C7c">On Sat, Jan 24, 2009 at 6:00 PM, Aleix Pol <span dir="ltr"><<a href="mailto:aleixpol@kde.org" target="_blank">aleixpol@kde.org</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="Wj3C7c">
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></div></div>_______________________________________________<br>
CMake mailing list<br>
<a href="mailto:CMake@cmake.org" target="_blank">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>
<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>