Boost C++ Libraries: Ticket #4959: Linking Serialization static lib to a DLL breaks auto-import in MinGW https://svn.boost.org/trac10/ticket/4959 <p> With MinGW GCC 4.51 and Boost 1.45, boost being compiled with the following command line: </p> <pre class="wiki">bjam toolset=gcc --build-type=complete --threading=multi variant=release link=static runtime-link=shared stage --stagedir=$RELEASE_LIB_DIR -j2 bjam toolset=gcc --build-type=complete --threading=multi variant=debug link=static runtime-link=shared stage --stagedir=$DEBUG_LIB_DIR -j2 </pre><p> The static serialization lib attaches "declspec(dllexport)" to some methods in boost/serialization/singleton.hpp, i.e. get_mutable_instance, get_const_instance and is_destroyed. </p> <p> This is OK if we link the static library against an executable. If we however link it against a DLL, GCC stops exporting automatically all the symbols in the source code of the DLL (auto-import feature), and switches to a linking mode where only those functions declared with "declspec(dllexport)" are exported. </p> <p> This is very inconvenient and hard to track if you use an automatic build environment like Boost Build (bjam). </p> <p> We fixed it adding the following lines to /boost/serialization/force_include.hpp: </p> <pre class="wiki">#if defined(BOOST_HAS_DECLSPEC) &amp;&amp; !defined(__COMO__) # if defined(__BORLANDC__) # define BOOST_DLLEXPORT __export # elif defined(__MINGW32__) // JOSE FIX !!!! # if defined(__GNUC__) &amp;&amp; (__GNUC__ &gt;= 3) # define BOOST_USED __attribute__ ((used)) # endif # else # define BOOST_DLLEXPORT __declspec(dllexport) # endif #elif ! defined(_WIN32) &amp;&amp; ! defined(_WIN64) # if defined(__MWERKS__) # define BOOST_DLLEXPORT __declspec(dllexport) # elif defined(__GNUC__) &amp;&amp; (__GNUC__ &gt;= 3) # define BOOST_USED __attribute__ ((used)) # elif defined(???????) &amp;&amp; (?????? &gt;= 1110) # define BOOST_USED __attribute__ ((used)) # elif defined(__INTEL_COMPILER) &amp;&amp; (BOOST_INTEL_CXX_VERSION &gt;= 800) # define BOOST_USED __attribute__ ((used)) # endif #endif </pre><p> You need to recompile the Boost Serialization static library with these changes, and make sure you have the modified force_include.hpp in the boost include that your apps use during compilation. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4959 Trac 1.4.3 Robert Ramey Wed, 15 Dec 2010 19:06:37 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/4959#comment:1 https://svn.boost.org/trac10/ticket/4959#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> this needs more analysis </p> <p> a) what is ??????? ? b) <em> JOSE FIX line will break normal gcc compilations </em></p> <p> Is one using "visibility" in the command line options? </p> <p> I believe that what is necessary is that the "force include" functionality be suppressed for builds of the library version of the DLLS. </p> <p> I realize that this is a problem, but I don't see enough information here to be able to address it. </p> <p> BTW - doesn't the definition of MINGW32 imply the definition of GNUC ? so I can't see how the suggested fix would change anything. </p> <p> Robert Ramey </p> Ticket jlcastillo@… Thu, 16 Dec 2010 12:04:56 GMT <link>https://svn.boost.org/trac10/ticket/4959#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4959#comment:2</guid> <description> <p> I realize my explanation may lead to misunderstanding. I'll try to elaborate it further. </p> <p> a) "????????" was addded in replacement of the original text, because <a class="wiki" href="https://svn.boost.org/trac10/wiki/WikiFormatting">WikiFormatting</a> complained about it (it seems there is some "intelligent" engine that rejects some words). It doesn't have any importance, just ignore it, you don't need to change those lines in the original file. </p> <p> b) The following lines are not present in the original /boost/serialization/force_include.hpp, and should be included: </p> <pre class="wiki"># elif defined(__MINGW32__) # if defined(__GNUC__) &amp;&amp; (__GNUC__ &gt;= 3) # define BOOST_USED __attribute__ ((used)) # endif </pre><p> As you state, we can possibly omit "defined(<span class="underline">GNUC</span>)", as it could be implicitly defined along with <span class="underline">MINGW32</span>. I left it just to keep the same structure that I saw below. I guess "(<span class="underline">GNUC</span> &gt;= 3)" should remain. </p> </description> <category>Ticket</category> </item> </channel> </rss>