Opened 14 years ago

Closed 11 years ago

#1871 closed Bugs (wontfix)

regex link error with msvc

Reported by: cedric.naniot@… Owned by: John Maddock
Milestone: Boost 1.36.0 Component: regex
Version: Boost 1.46.1 Severity: Problem
Keywords: Cc:

Description

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):

msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: thiscall std::allocator<unsigned short>::allocator<unsigned short>(void)" (??0?$allocator@G@std@@QAE@XZ) already defined in libboost_regex-vc80-mt-gd-1_34_1.lib(usinstances.obj)

Here is a sample to reproduce this issue :

#include <vector> #include <boost/regex.hpp>

int main() {

{

std::vector<wchar_t> Dummy; Dummy.push_back(12);

}

boost::wregex RegExp(L".*"); int Ret = boost::regex_search(L"jkfghsdhg", RegExp);

return Ret;

}

Attachments (3)

regex.patch (930 bytes ) - added by cedric.naniot@… 14 years ago.
workaround
regex.inc.patch (1.1 KB ) - added by François Barel 14 years ago.
Fix missing includes in c44842
bug.7z (994 bytes ) - added by dmitriy.ovdienko@… 12 years ago.
Project to reproduce bug

Download all attachments as: .zip

Change History (12)

by cedric.naniot@…, 14 years ago

Attachment: regex.patch added

workaround

comment:1 by John Maddock, 14 years ago

Resolution: fixed
Status: newclosed

Thanks for the report, fixed in Trunk with revision: http://svn.boost.org/trac/boost/changeset/44842

by François Barel, 14 years ago

Attachment: regex.inc.patch added

Fix missing includes in c44842

in reply to:  1 comment:2 by François Barel, 14 years ago

Resolution: fixed
Status: closedreopened

Replying to johnmaddock:

Thanks for the report, fixed in Trunk with revision: http://svn.boost.org/trac/boost/changeset/44842

With c44842 I now get an error when compiling libs/regex/src/wc_regex_traits.cpp in a DLL with VC9, because basic_string, char_traits and allocator are used without being defined (and I guess usinstances.cpp could suffer from the same problem).

The attached regex.inc.patch fixed it for me.

comment:3 by John Maddock, 14 years ago

Resolution: fixed
Status: reopenedclosed

Doh! Patch applied to Trunk.

John.

by dmitriy.ovdienko@…, 12 years ago

Attachment: bug.7z added

Project to reproduce bug

comment:4 by dmitriy.ovdienko@…, 12 years ago

I have same issue for boost 1.45 and 1.42. I'm compiling mixed .NET application using VS2008 and get error:

msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: thiscall std::allocator<unsigned short>::allocator<unsigned short>(void)" (??0?$allocator@G@std@@QAE@XZ) already defined in 2.obj

Please find sample of project attached.

comment:5 by anonymous, 12 years ago

Resolution: fixed
Status: closedreopened
Version: Boost 1.35.0Boost 1.45.0

comment:6 by anonymous, 12 years ago

Version: Boost 1.45.0Boost 1.46.1

Reproducible on boost 1.46.1.

comment:7 by John Maddock, 11 years ago

Resolution: invalid
Status: reopenedclosed

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.

Either - use regex as a dll, or, Compile everthing (including the regex lib) using the same options.

comment:8 by dmitriy.ovdienko@…, 11 years ago

Resolution: invalid
Status: closedreopened

you are linking *two different runtime libraries*

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.

Let me describe that:

cl /nologo /Iinclude/boost-1_45_0 /MDd /c /EHsc 2.cpp

  • Compiles 2.cpp with /MDd into 2.obj

cl /nologo /Iinclude/boost-1_45_0 /clr /LD /MDd 1.cpp 2.obj /link /LIBPATH:lib/x32

  • 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

Try linker switch /verbose to check that.

comment:9 by John Maddock, 11 years ago

Resolution: wontfix
Status: reopenedclosed

OK, can reproduce, but I don't have a fix that doesn't break something else.

This is caused by wc_regex_traits.cpp and usinstances.cpp which pull in declspec(dllexport) std::allocator<unsigned short>::allocator(), but then your source files result in std::allocator<unsigned short>::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.

There are two solutions:

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.

HTH, John.

Note: See TracTickets for help on using tickets.