Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
7669 Discussions

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

Michael_Wild
Beginner
172 Views
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
172 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
172 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
172 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
172 Views

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

thanks,
Jennifer

Reply