Boost C++ Libraries: Ticket #13326: linking with program_options has unresolved symbols on MSVC https://svn.boost.org/trac10/ticket/13326 <p> I'm developing a simple command line client application against boost::program_options. Everything works fine on Linux with gcc-4.8, gcc-5.3 and gcc-6.3, on Darwin with XCode 7 and on Windows with MinGW-w64. But on Windows with MSVC Build Tools 2017 x64 I get two unresolved symbols: </p> <pre class="wiki">LightBISClientCMDLine.cc.obj : error LNK2001: unresolved external symbol "class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; boost::program_options::arg" (?arg@program_options@boost@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) LightBISClientCMDLine.cc.obj : error LNK2001: unresolved external symbol "public: static unsigned int const boost::program_options::options_description::m_default_line_length" (?m_default_line_length@options_description@program_options@boost@@2IB) </pre><p> I checked program_options.dll and I am under the impression that those two symbols are defined there. I get exact matches for <code>?arg@program_options@boost@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A</code> and <code>?m_default_line_length@options_description@program_options@boost@@2IB</code>. Also all other symbols from program_options are resolved correctly. Here is the details build log with a verbose linker message: <a class="ext-link" href="http://data.biodataanalysis.de/tmp/boost_program_options_linker_error_emmenlau.txt"><span class="icon">​</span>http://data.biodataanalysis.de/tmp/boost_program_options_linker_error_emmenlau.txt</a> </p> <p> I am explictily setting preprocessor defines for debug, and I set to code to build for C++14. Is that possibly related? </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13326 Trac 1.4.3 Mario Emmenlauer <mario@…> Sun, 10 Dec 2017 09:03:25 GMT <link>https://svn.boost.org/trac10/ticket/13326#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13326#comment:1</guid> <description> <p> I investigated a bit and I think I found a new hint. As far as I could see, it's no longer supported to export STL classes from a DLL with Visual Studio 2017. There are various reports that indicate that exporting STL classes can cause issues when mixing different runtimes or compiler versions. Is it possible that Microsoft just disabled that option alltogether? </p> <p> I found related reports here: </p> <ul><li><a class="ext-link" href="https://social.msdn.microsoft.com/Forums/vstudio/en-US/df99b712-c00b-4af0-82fd-3764c8b6cbec/exporting-stdstring-from-a-dll-does-not-export-stdstringnpos"><span class="icon">​</span>https://social.msdn.microsoft.com/Forums/vstudio/en-US/df99b712-c00b-4af0-82fd-3764c8b6cbec/exporting-stdstring-from-a-dll-does-not-export-stdstringnpos</a> </li><li><a class="ext-link" href="https://stackoverflow.com/a/13866797/7200132"><span class="icon">​</span>https://stackoverflow.com/a/13866797/7200132</a> </li></ul> </description> <category>Ticket</category> </item> <item> <author>Mario Emmenlauer <mario@…></author> <pubDate>Mon, 12 Feb 2018 10:03:34 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13326#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13326#comment:2</guid> <description> <p> Is there any progress on this? I understand that it breaks use of program options with MSVC 2017, or am I doing something wrong? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Jakub</dc:creator> <pubDate>Thu, 22 Feb 2018 14:15:39 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13326#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13326#comment:3</guid> <description> <p> same problem here </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Vladimir Prus</dc:creator> <pubDate>Thu, 22 Feb 2018 16:50:01 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13326#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13326#comment:4</guid> <description> <p> Could you provide the minimal example (source, build command) that reproduces this? </p> </description> <category>Ticket</category> </item> <item> <author>Mario Emmenlauer <mario@…></author> <pubDate>Tue, 27 Feb 2018 16:22:58 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13326#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13326#comment:5</guid> <description> <p> Here is an example that shows the error. The build is configured with cmake. <a class="ext-link" href="https://github.com/emmenlau/BDAMinimalTestCase"><span class="icon">​</span>https://github.com/emmenlau/BDAMinimalTestCase</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 20 Mar 2018 12:24:43 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13326#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13326#comment:6</guid> <description> <p> It looks to me the commit 1f9413f532e58b82d12e9185c2eb8bc45612914c is the culprit. I could not paste the github link here as the system complained it is external link. github&lt;add .com&gt; /boostorg/program_options/commit/1f9413f532e58b82d12e9185c2eb8bc45612914c In my local build with that reverted, the program_options.lib is generated. </p> <p> What's the rationale for that commit? </p> </description> <category>Ticket</category> </item> <item> <author>Mario Emmenlauer <mario@…></author> <pubDate>Tue, 20 Mar 2018 15:38:11 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13326#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13326#comment:7</guid> <description> <p> Its an interesting find that this causing the build problem. But according to my understanding, exporting STL classes from a DLL (or other shared library) is generally not a good idea. </p> <p> As quoted from Stackoverflow: Various articles seems to indicate that this is very bad, which is quite understandable. Everything must be compiled with the same compiler settings and CRT version. Otherwise everything will crash and burn. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Vladimir Prus</dc:creator> <pubDate>Thu, 22 Mar 2018 15:22:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13326#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13326#comment:8</guid> <description> <p> I am not sure it's a problem with STL classes - the two unresolved references are not STL classes, they are static members of program_options classes. When building program_options, <code>-DBOOST_PROGRAM_OPTIONS_DYN_LINK=1</code> must be set, otherwise these two are not marked as exported, and this error occurs. </p> <p> Commit 1f9413 indeed broke things, but it was then fixed in <a class="ext-link" href="https://github.com/boostorg/boost/commit/a696afede9da8dbf0e3084ad07585148903bfaca"><span class="icon">​</span>https://github.com/boostorg/boost/commit/a696afede9da8dbf0e3084ad07585148903bfaca</a> </p> <p> So, the first step in diagnosing this issue would be to go to libs/program_options/build, run <code>b2 toolset=msvc link=shared -n</code> and see whether the library is built with <code>-DBOOST_PROGRAM_OPTIONS_DYN_LINK=1</code> or not. </p> </description> <category>Ticket</category> </item> <item> <author>Mario Emmenlauer <mario@…></author> <pubDate>Thu, 22 Mar 2018 16:17:19 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13326#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13326#comment:9</guid> <description> <p> Dear Vladimir, thanks for your help. But one question: I checked program_options.dll and I am under the impression that those two symbols are defined there. I get exact matches for <code>?arg@program_options@boost@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A</code> and <code>?m_default_line_length@options_description@program_options@boost@@2IB</code> in program_options.dll. Should that not imply that the export worked, but the linker does not accept these symbols? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Vladimir Prus</dc:creator> <pubDate>Fri, 23 Mar 2018 07:36:26 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13326#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13326#comment:10</guid> <description> <p> boost_program_options.dll is expected to have these symbols at all times, however the linker is not using .dll, it's using import library, usually boost_program_options.lib. When building without -DBOOST_PROGRAM_OPTIONS_DYN_LINK=1, the import library does not mention these symbols, and the linker cannot find them. </p> <p> There could be other issues, maybe specific to VC 2017, but the first thing we need to determine if <code>-DBOOST_PROGRAM_OPTIONS_DYN_LINK=1</code> is used. If not, nothing is gonna work. </p> </description> <category>Ticket</category> </item> <item> <author>Mario Emmenlauer <mario@…></author> <pubDate>Fri, 06 Apr 2018 20:59:58 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13326#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13326#comment:11</guid> <description> <p> Ok I did as you suggested and added -n to the build options. Then I get </p> <pre class="wiki">#&gt; grep BOOST_PROGRAM_OPTIONS_DYN_LINK /tmp/buildlog.txt -DBOOST_PROGRAM_OPTIONS_DYN_LINK=1 -DBOOST_PROGRAM_OPTIONS_DYN_LINK=1 -DBOOST_PROGRAM_OPTIONS_DYN_LINK=1 -DBOOST_PROGRAM_OPTIONS_DYN_LINK=1 -DBOOST_PROGRAM_OPTIONS_DYN_LINK=1 -DBOOST_PROGRAM_OPTIONS_DYN_LINK=1 -DBOOST_PROGRAM_OPTIONS_DYN_LINK=1 -DBOOST_PROGRAM_OPTIONS_DYN_LINK=1 -DBOOST_PROGRAM_OPTIONS_DYN_LINK=1 -DBOOST_PROGRAM_OPTIONS_DYN_LINK=1 -DBOOST_PROGRAM_OPTIONS_DYN_LINK=1 </pre><p> Do you need the full build log? </p> </description> <category>Ticket</category> </item> <item> <author>Mario Emmenlauer <mario@…></author> <pubDate>Wed, 18 Apr 2018 19:54:06 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13326#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13326#comment:12</guid> <description> <p> So do I understand correctly that the symbols should be there because the flag is present as expected? Anything I can do to help? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 24 May 2018 00:43:50 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13326#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13326#comment:13</guid> <description> <p> Hi, </p> <p> thanks for details. </p> <p> I am using boost 1.64, library program_options.lib does contain the unresolved symbols pointed out in VS link errors. Still I am facing the same issue. Do i need to build the library again with DBOOST_PROGRAM_OPTIONS_DYN_LINK=1 option. </p> </description> <category>Ticket</category> </item> <item> <author>Mario Emmenlauer <mario@…></author> <pubDate>Sat, 07 Jul 2018 11:57:52 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13326#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13326#comment:14</guid> <description> <p> Is there progress on this issue? I can not use boost::program_options shared build on MSVC with any compiler since 2015 (tested with MSVC 2015, MSVC2017 and Intel Compiler for Windows). </p> </description> <category>Ticket</category> </item> </channel> </rss>