Boost C++ Libraries: Ticket #12417: Linking dynamically to boost::locale::info class on Windows fails when auto-linking is disabled https://svn.boost.org/trac10/ticket/12417 <p> There appears to be a name-mangling issue in boost::locale::info related to a public static member variable of type std::locale::id, only when linking to the DLL on Windows. When using auto-linking, there is no problem. </p> <h2 class="section" id="Setup">Setup</h2> <p> Boost 1.61 (tested on both pre-built and from-source libraries), Windows 10 x64, MSVC 2015 (cl 19.00.24213.1), using x64 compiler. </p> <h2 class="section" id="Code">Code</h2> <p> bugtest.cc </p> <pre class="wiki">#include &lt;boost/locale.hpp&gt; #include &lt;iostream&gt; int main() { std::locale::global(boost::locale::generator().generate("en_US.UTF-8")); std::cout &lt;&lt; std::use_facet&lt;boost::locale::info&gt;(std::locale()).name() &lt;&lt; std::endl; } </pre><h2 class="section" id="CompilerCommand">Compiler Command</h2> <pre class="wiki">cl.exe -IC:\Boost\include\boost-1_61 -DBOOST_ALL_NO_LIB -EHsc -O2 bugtest.cc -link -libpath:c:\Boost\lib boost_locale-vc140-mt-1_61.lib </pre><h2 class="section" id="LinkerFailure">Linker Failure</h2> <p> bugtest.obj : error LNK2019: unresolved external symbol "public: static class std::locale::id boost::locale::info::id" (?id@info@locale@boost@@2V02std@@A) referenced in function "class boost::locale::info const &amp; <span class="underline">cdecl std::use_facet&lt;class boost::locale::info&gt;(class std::locale const &amp;)" (??$use_facet@Vinfo@locale@boost@@@std@@YAAEBVinfo@locale@boost@@AEBV20@@Z) bugtest.exe : fatal error LNK1120: 1 unresolved externals </span></p> <h2 class="section" id="Workaround">Workaround</h2> <p> Force dllimport attribute </p> <pre class="wiki">cl.exe -IC:\Boost\include\boost-1_61 -DBOOST_LOCALE_DECL=__declspec(dllimport) -DBOOST_ALL_NO_LIB -EHsc -O2 bugtest.cc -link -libpath:c:\Boost\lib boost_locale-vc140-mt-1_61.lib </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12417 Trac 1.4.3 anonymous Mon, 29 Aug 2016 07:08:22 GMT summary changed https://svn.boost.org/trac10/ticket/12417#comment:1 https://svn.boost.org/trac10/ticket/12417#comment:1 <ul> <li><strong>summary</strong> <span class="trac-field-old">Linking dynamically to boost::locale::info class on Windows fails when auto-linking is diasbled</span> → <span class="trac-field-new">Linking dynamically to boost::locale::info class on Windows fails when auto-linking is disabled</span> </li> </ul> Ticket Artyom Beilis Mon, 29 Aug 2016 07:13:06 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/12417#comment:2 https://svn.boost.org/trac10/ticket/12417#comment:2 <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> You need to add <code>BOOST_ALL_DYN_LINK</code> or <code>BOOST_LOCALE_DYN_LINK</code> definition for your windows projects when linking with DLLs so dllimport will be defined properly. </p> <p> It is general rule for all boost libraries. </p> Ticket anonymous Mon, 29 Aug 2016 07:24:44 GMT <link>https://svn.boost.org/trac10/ticket/12417#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12417#comment:3</guid> <description> <p> That's fine, but then the documentation should reflect that turning off auto-linking for DLLs on Windows is an unsupported option. I would expect it to work if linking to the correct import library. </p> </description> <category>Ticket</category> </item> </channel> </rss>