Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Michael_Wild
Beginner
73 Views

Multiply defined symbols error when using std::tr1::regex from VS 2008 SP1

Hi all

If I try to use std::tr1::regex in more than one compilation unit I get a linker error because the static member data std::tr1::_Regex_traits::_Names gets instantiated in each of the object files since the definition of the explicit specialization is in the header.

Strangely, this works when using the Microsoft compiler. Anybody got an idea how to resolve this issue?

Michael

PS: This is with

  • Windows 7
  • Visual Studio 2008 SP1
  • Intel C++ Compiler 11.1.046
0 Kudos
4 Replies
Michael_Wild
Beginner
73 Views

A simple example would be the following:

main.cpp:
[cpp]#include 

// This function is defined in foo.cpp and also
// uses std::tr1::regex
void foo();

int main(int argc, char* argv[])
{
	std::tr1::regex re("^Hello World!$", std::tr1::regex::extended);
	std::tr1::regex_match("Hello World!", re);
	foo();
	return 0;
}[/cpp]

foo.cpp:
[cpp]#include 

void foo()
{
	std::tr1::regex re("African");
	bool match = std::tr1::regex_search("European or African?", re);
}[/cpp]
JenniferJ
Moderator
73 Views

Yeh, I saw the issue too.

Thanks for reporting it and the testcase. I'll report it to the compiler engineering team. if there's any news, I'll let you know. At this moment, I don't know of any work-around.

Thanks again.
Jennifer
Michael_Wild
Beginner
73 Views

Thanks!

As a work-around (more like a cludge) I resorted to #include all the files that use into one single master-file instead of compiling them directly.

Michael
JenniferJ
Moderator
73 Views

Hello,
this issue has been fixed in our 12.0 compiler. the initial release should contain the fix.

thanks,
Jennifer

Reply