Boost C++ Libraries: Ticket #12233: boost::regex doesn't compile with clang on windows https://svn.boost.org/trac10/ticket/12233 <p> Trying to compile a simple example: </p> <pre class="wiki">#include &lt;boost/regex.hpp&gt; #include &lt;string&gt; #include &lt;iostream&gt; int main() { std::string s = "Boost Libraries"; boost::regex expr{"\\w+\\s\\w+"}; std::cout &lt;&lt; std::boolalpha &lt;&lt; boost::regex_match(s, expr) &lt;&lt; '\n'; } </pre><p> with </p> <pre class="wiki">latte ~\Desktop &gt; clang-cl /D_CRT_SECURE_NO_WARNINGS /MT -I C:\boost-1.61.0 .\b2.cpp C:\boost-1.61.0\lib64-msvc-14.0\lib boost_regex-vc140-mt-s-1_61.lib b2-807015.obj : error LNK2019: unresolved external symbol "public: bool __cdecl boost::re_detail_106100::abstract_protected_call::execute(void)const " (?execute@abstract_protected_call@re_detail_106100@boost@@QEBA_NXZ) referenced in function "private: bool __cdecl boost::re_detail_106100::perl_matcher&lt;class std::_String_const_iterator&lt;class std::_String_val&lt;struct std::_Simple_types&lt;char&gt; &gt; &gt;,class std::allocator&lt;struct boost::sub_match&lt;class std::_String_const_iterator&lt;class std::_String_val&lt;struct std::_Simple_types&lt;char&gt; &gt; &gt; &gt; &gt;,struct boost::regex_traits&lt;char,class boost::w32_regex_traits&lt;char&gt; &gt; &gt;::protected_call(bool (__cdecl boost::re_detail_106100::perl_matcher&lt;class std::_String_const_iterator&lt;class std::_String_val&lt;struct std::_Simple_types&lt;char&gt; &gt; &gt;,class std::allocator&lt;struct boost::sub_match&lt;class std::_String_const_iterator&lt;class std::_String_val&lt;struct std::_Simple_types&lt;char&gt; &gt; &gt; &gt; &gt;,struct boost::regex_traits&lt;char,class boost::w32_regex_traits&lt;char&gt; &gt; &gt;::*)(void))" (?protected_call@?$perl_matcher@V?$_String_const_iterator@V?$_String_val@U?$_Simple_types@D@std@@@std@@@std@@V?$allocator@U?$sub_match@V?$_String_const_iterator@V?$_String_val@U?$_Simple_types@D@std@@@std@@@std@@@boost@@@2@U?$regex_traits@DV?$w32_regex_traits@D@boost@@@boost@@@re_detail_106100@boost@@AEAA_NP8123@EAA_NXZ@Z) b2.exe : fatal error LNK1120: 1 unresolved externals clang-cl.exe: error: linker command failed with exit code 1120 (use -v to see invocation) </pre><p> This is also reproducible with clang.exe. Test system is Windows 10 x64. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12233 Trac 1.4.3 juandent@… Sat, 28 May 2016 21:14:49 GMT <link>https://svn.boost.org/trac10/ticket/12233#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12233#comment:1</guid> <description> <p> Hi, I also find unresolved external symbols when I try to link with Boost when compiling with Clang 3.7 with Microsoft <a class="missing wiki">CodeGen</a>. Couldn't it be that the Boost libraries were built with the usual Microsoft instead of clang? </p> <p> Or did you build your Boost libraries with Clang 3.7? If so, can you explain me how? Did you create a VStudio 2015 Update 2 solution to build Boost? Where did you get such solution? If you used CMake to generate VStudio projects, where did you get the CMAkeLists.txt files? </p> <p> I hope we can find the solution to this together! </p> <p> Regards, Juan </p> </description> <category>Ticket</category> </item> <item> <author>juandent@…</author> <pubDate>Sat, 28 May 2016 21:14:55 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12233#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12233#comment:1</guid> <description> <p> Hi, I also find unresolved external symbols when I try to link with Boost when compiling with Clang 3.7 with Microsoft <a class="missing wiki">CodeGen</a>. Couldn't it be that the Boost libraries were built with the usual Microsoft instead of clang? </p> <p> Or did you build your Boost libraries with Clang 3.7? If so, can you explain me how? Did you create a VStudio 2015 Update 2 solution to build Boost? Where did you get such solution? If you used CMake to generate VStudio projects, where did you get the CMAkeLists.txt files? </p> <p> I hope we can find the solution to this together! </p> <p> Regards, Juan </p> </description> <category>Ticket</category> </item> <item> <author>juandent@…</author> <pubDate>Sat, 28 May 2016 21:15:03 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12233#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12233#comment:1</guid> <description> <p> Hi, I also find unresolved external symbols when I try to link with Boost when compiling with Clang 3.7 with Microsoft <a class="missing wiki">CodeGen</a>. Couldn't it be that the Boost libraries were built with the usual Microsoft instead of clang? </p> <p> Or did you build your Boost libraries with Clang 3.7? If so, can you explain me how? Did you create a VStudio 2015 Update 2 solution to build Boost? Where did you get such solution? If you used CMake to generate VStudio projects, where did you get the CMAkeLists.txt files? </p> <p> I hope we can find the solution to this together! </p> <p> Regards, Juan </p> </description> <category>Ticket</category> </item> <item> <author>İsmail Dönmez <ismail@…></author> <pubDate>Sun, 29 May 2016 06:29:20 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12233#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12233#comment:2</guid> <description> <p> I used the precompiled VC14 binaries with clang 3.9 from trunk. Building boost clang is really a different topic because I think it's currently unsupported. Though clang has full VC++ ABI compatibility which should work in this case too. </p> <p> All but this one symbol is missing: </p> <pre class="wiki">public: bool __cdecl boost::re_detail_106100::abstract_protected_call::execute(void)const </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Mon, 30 May 2016 07:31:03 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12233#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12233#comment:3</guid> <description> <p> I'm not sure this is ever going to work - you would need to build regex with clang as well. </p> <p> Note that the regex source is "just a bunch of source files", you can build the source in libs/regex/src/*.cpp using whatever method you wish. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 30 May 2016 07:43:57 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12233#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12233#comment:4</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/12233#comment:3" title="Comment 3">johnmaddock</a>: </p> <blockquote class="citation"> <p> I'm not sure this is ever going to work - you would need to build regex with clang as well. </p> <p> Note that the regex source is "just a bunch of source files", you can build the source in libs/regex/src/*.cpp using whatever method you wish. </p> </blockquote> <p> Just to be on the same page I don't claim this to be a boost bug, I am just trying to understand how is the boost::re_detail_106100::abstract_protected_call::execute symbol is special since clang can't find it. Any tips for me before I look at the source code? </p> <p> Thanks! </p> </description> <category>Ticket</category> </item> <item> <author>İsmail Dönmez <ismail@…></author> <pubDate>Mon, 30 May 2016 11:04:15 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12233#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12233#comment:5</guid> <description> <p> This works when compiling everything with clang so it's surely a bug in clang's MSVC compat. Please feel free to close this bug, I'll be reporting a clang bug when I find the problem. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Mon, 30 May 2016 11:52:58 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12233#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12233#comment:6</guid> <description> <p> Not necessarily a clang bug - I suspect we don't have MSVC and clang configured in exactly the same way - for that matter I'm not sure we would want to (as it would mean disabling clang features), but unless the two compilers are identically configured in Boost.Config etc you won't get binary-compatible objects. </p> </description> <category>Ticket</category> </item> <item> <author>İsmail Dönmez <ismail@…></author> <pubDate>Mon, 30 May 2016 11:56:59 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12233#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12233#comment:7</guid> <description> <p> clang-cl.exe is supposed to be a drop in replacement for cl.exe including binary compatibility. Any difference is a bug. I will update this bug after reporting the relevant clang bug. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Mon, 30 May 2016 12:39:41 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12233#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12233#comment:8</guid> <description> <p> You're missing the point: we don't configure clang and msvc the same so the libraries won't contain the same symbols. </p> </description> <category>Ticket</category> </item> <item> <author>İsmail Dönmez <ismail@…></author> <pubDate>Mon, 30 May 2016 12:41:49 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12233#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12233#comment:9</guid> <description> <p> Then as I currently suspect boost "needs" something like BOOST_CLANG_CL akin to BOOST_MSVC which enables clang features + MSVC features supported. </p> </description> <category>Ticket</category> </item> <item> <author>adamf88@…</author> <pubDate>Wed, 19 Oct 2016 21:23:19 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12233#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12233#comment:10</guid> <description> <p> Hi eceryone, </p> <p> I found the same issue. I have boost compiled with MSVC toolset (2010) and I'm trying to link it to project with clang toolset. I have no problems with libraries like boost::filesystem. The regexp is the first one I found problem. </p> <p> I had some time (it took a while) to debug it, but finally I found the reason (if you want to read it in a nutshell then scroll down to point 5): </p> <ol><li>The error message says than abstract_protected_call::execute() is missing from regex.cpp in the library. I checked the generated libboost_regex-vc100-mt-gd-1_62.lib file. This is true, this function is missing. But why MSVC compilation works and Clang doesn't ? </li><li>To answer the question we have to look around. This function is guarded by define: BOOST_REGEX_HAS_MS_STACK_GUARD. If we get the things together then: on MSVC toolset BOOST_REGEX_HAS_MS_STACK_GUARD is undefined (because in lib is missing) and on clang the symbol is defined (because it looks for this function). Let's check it </li><li>The symbol is defined in file regex\config.hxx. (line 370 in boost 1.62.0). For tests I added pragma line above this definition: #pragma message("TEST") then we will get this message on clang build and during regex compilation with MSVC. (So the function execute should be available because the symbol is defined), but: </li><li>In line 417 in file config.hpp we can find: </li></ol><pre class="wiki"># ifdef BOOST_REGEX_HAS_MS_STACK_GUARD # undef BOOST_REGEX_HAS_MS_STACK_GUARD # endif </pre><p> Lets add #pragma message ("UNDEFINED") and check when it is executed. Finally: MSVC compilation boost::regexp library - we will get message UNDEFINED. So the symbol is undefined and our method is not available in static lib. Clang (test project compilation with regexp) - no message. So symbol BOOST_REGEX_HAS_MS_STACK_GUARD is still defined and clang tries to link this function (execute). </p> <ol start="5"><li>Where is the difference ? </li></ol><p> In line 395 (regex/config.hpp) we can find define with statement (this statement enables undef code block execution): </p> <pre class="wiki">!(defined(BOOST_MSVC) &amp;&amp; (BOOST_MSVC &gt;= 1400) </pre><p> If we build sample project with Clang toolset then BOOST_MSVC is undefined. And it is the reason why the compilation fails. Why this symbol is undefined ? Clang should pretend to be MSVC perfectly ( really ? :) ). To answer this last question we should look into file: "config/select_compiler_config.hpp". Clang on windows defines symbols: <span class="underline">clang</span> and _MSC_VER, but the check for clang is before check for MSVC and clang toolset was selected. So boost doesn't define BOOST_MSVC for clang toolset compilation. </p> <p> Unfortunately clang doesn't pretend to be MSVC perfectly and it caused the error. I hope it will help you to do the fix. </p> <p> My quick and dirty fix was in select_compiler_config.hpp file by adding on the end of clang toolset checking: &amp;&amp; !defined(_MSC_VER). But I didn't run any other tests and I don't know if it doesn't cause any other issues. ( My program now works :) ) </p> <p> Dear boost support: Will you do any fix of this issue in the next versions of boost library ? Do you have any plans to support boost build with clang toolset on windows ? </p> <p> Regards, Adam </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Wed, 08 Feb 2017 19:38:15 GMT</pubDate> <title>status, milestone changed; resolution set https://svn.boost.org/trac10/ticket/12233#comment:11 https://svn.boost.org/trac10/ticket/12233#comment:11 <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">fixed</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.64.0</span> </li> </ul> <p> I believe this is now fixed in <a class="ext-link" href="https://github.com/boostorg/regex/commit/4bfdae4a9f7ca8b74dba4da3ba09d376d260e19f"><span class="icon">​</span>https://github.com/boostorg/regex/commit/4bfdae4a9f7ca8b74dba4da3ba09d376d260e19f</a> </p> Ticket