Boost C++ Libraries: Ticket #603: regex linking error with VC 7.1 https://svn.boost.org/trac10/ticket/603 <pre class="wiki">I see this error when linking against libboost_regex-vc71-mt-1_33_1.lib: msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: static unsigned int __cdecl std::char_traits&lt;unsigned short&gt;::length(unsigned short const *)" (?length@?$char_traits@G@std@@SAIPBG@Z) already defined in libboost_regex-vc71-mt-1_33_1.lib(usinstances.obj) libs/regex/src/usinstances.cpp appears to have problems. Steps to reproduce: - Create a console project with VC7.1. - Set Character Set to "Use Unicode Character Set" - Use a Multi-threaded DLL - Link against libboost_regex-vc71-mt-1_33_1.lib - wchar_t should NOT be set as a native type - Use the following code: #include "stdafx.h" #include &lt;string&gt; #include &lt;boost/regex.hpp&gt; int _tmain(int argc, _TCHAR* argv[]) { #if _UNICODE std::wstring strCurLine(L"sdfsdfggg"); std::wstring strMatchExp(L"lsdfkjsflk"); boost::wcmatch Matched; boost::wregex regex(strMatchExp.c_str()); #else std::string strCurLine("sdfsdfggg"); std::string strMatchExp("lsdfkjsflk"); boost::cmatch Matched; boost::regex regex(strMatchExp.c_str()); #endif boost::regex_search(strCurLine.c_str(), Matched, regex); return 0; } There are no linking errors if you build with wchar_t as a native type or build with character set as "Use Mutli-Byte Character Set". </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/603 Trac 1.4.3 John Maddock Sat, 15 Apr 2006 10:18:12 GMT <link>https://svn.boost.org/trac10/ticket/603#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/603#comment:1</guid> <description> <pre class="wiki">Logged In: YES user_id=14804 I can reproduce this, unfortunately I don't see any solution: when building with the mutibyte character set the instantiations of char_traits&lt;unsigned short&gt; in usinstances.cpp are absolutely required. And when building with the Unicode character set they cause the issues you spotted. The only solution I can see is for you to comment out the lines starting with #ifdef _DLL_CPPLIB in usinstances.cpp if you want to use that build configuration (of course other build configurations may then result in those symbols being undefined). I'm going to leave this issue open, in the hopes that someone might come up with a solution. John Maddock. </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Sat, 15 Apr 2006 17:19:12 GMT</pubDate> <title>status changed https://svn.boost.org/trac10/ticket/603#comment:2 https://svn.boost.org/trac10/ticket/603#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> </ul> <pre class="wiki">Logged In: YES user_id=14804 Apologies, but ignore everything in my last message: you can work around this quite easily by building the regex lib without /Zc:wchar_t, or by adding the line: template&lt;&gt; _CRTIMP2 std::size_t __cdecl char_traits&lt;unsigned short&gt;::length(unsigned short const*); to the end of the other specializations in usinstances.cpp (this is the fix that's going into cvs any minute now). John Maddock </pre> Ticket nmwcosteve Tue, 21 Nov 2006 21:43:20 GMT <link>https://svn.boost.org/trac10/ticket/603#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/603#comment:3</guid> <description> <pre class="wiki">Logged In: YES user_id=1651027 Originator: NO I have taken the fix as it appears in the 1_34 alpha. It does not appear to be working, at least for me in VC8. I get LNK2005 errors: error LNK2005: "public: static unsigned int __cdecl std::char_traits&lt;unsigned short&gt;::length(unsigned short const *)" (?length@?$char_traits@G@std@@SAIPBG@Z) already defined in msvcprtd.lib(MSVCP80D.dll) error LNK2005: "public: __thiscall std::allocator&lt;unsigned short&gt;::allocator&lt;unsigned short&gt;(void)" (??0?$allocator@G@std@@QAE@XZ) already defined in msvcprtd.lib(MSVCP80D.dll) I need to build Unicode, with /Zc:wchar_t- to be compatible with our existing codeset. Perhaps this is a different problem? </pre> </description> <category>Ticket</category> </item> </channel> </rss>