Opened 17 years ago

Closed 17 years ago

Last modified 16 years ago

#603 closed Bugs (Fixed)

regex linking error with VC 7.1

Reported by: nobody Owned by: John Maddock
Milestone: Component: regex
Version: None Severity:
Keywords: Cc:

Description

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<unsigned
short>::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 <string>
#include <boost/regex.hpp>

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".

Change History (3)

comment:1 by John Maddock, 17 years ago

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<unsigned short> 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.

comment:2 by John Maddock, 17 years ago

Status: assignedclosed
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<> _CRTIMP2 std::size_t __cdecl char_traits<unsigned
short>::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

comment:3 by nmwcosteve, 16 years ago

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<unsigned short>::length(unsigned short const *)" (?length@?$char_traits@G@std@@SAIPBG@Z) already defined in msvcprtd.lib(MSVCP80D.dll)

error LNK2005: "public: __thiscall std::allocator<unsigned short>::allocator<unsigned short>(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?
Note: See TracTickets for help on using tickets.