Boost C++ Libraries: Ticket #1871: regex link error with msvc https://svn.boost.org/trac10/ticket/1871 <p> With msvc 8 and 9 using regex (Boost 1.34.1 and 1.35) in code compiled with /Zc:wchar_t- result in the following error (multi-threaded DLL): </p> <p> msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: <span class="underline">thiscall std::allocator&lt;unsigned short&gt;::allocator&lt;unsigned short&gt;(void)" (??0?$allocator@G@std@@QAE@XZ) already defined in libboost_regex-vc80-mt-gd-1_34_1.lib(usinstances.obj) </span></p> <p> Here is a sample to reproduce this issue : </p> <p> #include &lt;vector&gt; #include &lt;boost/regex.hpp&gt; </p> <p> int main() { </p> <blockquote> <p> { </p> <blockquote> <p> std::vector&lt;wchar_t&gt; Dummy; Dummy.push_back(12); </p> </blockquote> <p> } </p> </blockquote> <blockquote> <p> boost::wregex <a class="missing wiki">RegExp</a>(L".*"); int Ret = boost::regex_search(L"jkfghsdhg", <a class="missing wiki">RegExp</a>); </p> </blockquote> <blockquote> <p> return Ret; </p> </blockquote> <p> } </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1871 Trac 1.4.3 cedric.naniot@… Sun, 27 Apr 2008 16:25:55 GMT attachment set https://svn.boost.org/trac10/ticket/1871 https://svn.boost.org/trac10/ticket/1871 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">regex.patch</span> </li> </ul> <p> workaround </p> Ticket John Maddock Mon, 28 Apr 2008 11:09:38 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/1871#comment:1 https://svn.boost.org/trac10/ticket/1871#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">fixed</span> </li> </ul> <p> Thanks for the report, fixed in Trunk with revision: <a class="ext-link" href="http://svn.boost.org/trac/boost/changeset/44842"><span class="icon">​</span>http://svn.boost.org/trac/boost/changeset/44842</a> </p> Ticket François Barel Tue, 13 May 2008 17:21:37 GMT attachment set https://svn.boost.org/trac10/ticket/1871 https://svn.boost.org/trac10/ticket/1871 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">regex.inc.patch</span> </li> </ul> <p> Fix missing includes in c44842 </p> Ticket François Barel Tue, 13 May 2008 17:24:06 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/1871#comment:2 https://svn.boost.org/trac10/ticket/1871#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/1871#comment:1" title="Comment 1">johnmaddock</a>: </p> <blockquote class="citation"> <p> Thanks for the report, fixed in Trunk with revision: <a class="ext-link" href="http://svn.boost.org/trac/boost/changeset/44842"><span class="icon">​</span>http://svn.boost.org/trac/boost/changeset/44842</a> </p> </blockquote> <p> With c44842 I now get an error when compiling <em>libs/regex/src/wc_regex_traits.cpp</em> in a DLL with VC9, because <code>basic_string</code>, <code>char_traits</code> and <code>allocator</code> are used without being defined (and I guess <em>usinstances.cpp</em> could suffer from the same problem). </p> <p> The attached <em>regex.inc.patch</em> fixed it for me. </p> Ticket John Maddock Wed, 14 May 2008 11:16:40 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/1871#comment:3 https://svn.boost.org/trac10/ticket/1871#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Doh! Patch applied to Trunk. </p> <p> John. </p> Ticket dmitriy.ovdienko@… Wed, 06 Apr 2011 15:04:43 GMT attachment set https://svn.boost.org/trac10/ticket/1871 https://svn.boost.org/trac10/ticket/1871 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">bug.7z</span> </li> </ul> <p> Project to reproduce bug </p> Ticket dmitriy.ovdienko@… Wed, 06 Apr 2011 15:09:18 GMT <link>https://svn.boost.org/trac10/ticket/1871#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1871#comment:4</guid> <description> <p> I have same issue for boost 1.45 and 1.42. I'm compiling mixed .NET application using VS2008 and get error: </p> <p> msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: <span class="underline">thiscall std::allocator&lt;unsigned short&gt;::allocator&lt;unsigned short&gt;(void)" (??0?$allocator@G@std@@QAE@XZ) already defined in 2.obj </span></p> <p> Please find sample of project attached. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 06 Apr 2011 15:10:23 GMT</pubDate> <title>status, version changed; resolution deleted https://svn.boost.org/trac10/ticket/1871#comment:5 https://svn.boost.org/trac10/ticket/1871#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>version</strong> <span class="trac-field-old">Boost 1.35.0</span> → <span class="trac-field-new">Boost 1.45.0</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> Ticket anonymous Wed, 06 Apr 2011 15:12:50 GMT version changed https://svn.boost.org/trac10/ticket/1871#comment:6 https://svn.boost.org/trac10/ticket/1871#comment:6 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.45.0</span> → <span class="trac-field-new">Boost 1.46.1</span> </li> </ul> <p> Reproducible on boost 1.46.1. </p> Ticket John Maddock Mon, 25 Apr 2011 09:04:42 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/1871#comment:7 https://svn.boost.org/trac10/ticket/1871#comment:7 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> This isn't really a regex lib issue - you are linking *two different runtime libraries* in the same program - and you just can't do that. Period. Ever. Even if you get it to link it probably won't run correctly. </p> <p> Either - use regex as a dll, or, Compile everthing (including the regex lib) using the same options. </p> Ticket dmitriy.ovdienko@… Tue, 26 Apr 2011 09:03:23 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/1871#comment:8 https://svn.boost.org/trac10/ticket/1871#comment:8 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">invalid</span> </li> </ul> <blockquote class="citation"> <p> you are linking *two different runtime libraries* </p> </blockquote> <p> I'm building mixed .NET application. Part of the code is built as native C++ code (2.cpp). Part of the code is built as C++/CLI (1.cpp). Runtime *is the same* Multithreaded debug DLL (/MDd). I'm linking regex as static debug library. </p> <p> Let me describe that: </p> <p> cl /nologo /Iinclude/boost-1_45_0 /MDd /c /EHsc 2.cpp </p> <ul><li>Compiles 2.cpp with /MDd into 2.obj </li></ul><p> cl /nologo /Iinclude/boost-1_45_0 /clr /LD /MDd 1.cpp 2.obj /link /LIBPATH:lib/x32 </p> <ul><li>Compiles 1.cpp with /MDd as C++/CLI code, links 2.obj and libboost_regex-vc90-mt-gd-1_45.lib into .NET assembly 1.dll </li></ul><p> Try linker switch /verbose to check that. </p> Ticket John Maddock Mon, 09 May 2011 17:07:10 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/1871#comment:9 https://svn.boost.org/trac10/ticket/1871#comment:9 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> OK, can reproduce, but I don't have a fix that doesn't break something else. </p> <p> This is caused by wc_regex_traits.cpp and usinstances.cpp which pull in <span class="underline">declspec(dllexport) std::allocator&lt;unsigned short&gt;::allocator(), but then your source files result in std::allocator&lt;unsigned short&gt;::allocator() (without the dllimport) being defined and hence the clash. In other words it's caused by MS's headers getting in a pickle and defining symbols differently depending what compiler options are used. </span></p> <p> There are two solutions: </p> <p> Manually add the regex source files to your project with the exception of cw_regex_traits.cpp and usinstances.cpp, or build everything with BOOST_REGEX_DYN_LINK defined and link to the regex dll rather than the static lib. </p> <p> HTH, John. </p> Ticket