Opened 14 years ago
Closed 11 years ago
#1871 closed Bugs (wontfix)
regex link error with msvc
Reported by: | 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)
Change History (12)
by , 14 years ago
Attachment: | regex.patch added |
---|
follow-up: 2 comment:1 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Thanks for the report, fixed in Trunk with revision: http://svn.boost.org/trac/boost/changeset/44842
comment:2 by , 14 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
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 , 14 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Doh! Patch applied to Trunk.
John.
comment:4 by , 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 , 12 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Version: | Boost 1.35.0 → Boost 1.45.0 |
comment:7 by , 11 years ago
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
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 , 11 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
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 , 11 years ago
Resolution: | → wontfix |
---|---|
Status: | reopened → closed |
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.
workaround