I observered some strange error, when I migrated my projects from VS2013. Here is simplified code of a newly created project to reproduce it:
A.cpp
:#include <iostream>
extern void foo();
int main()
{
std::cout << "some text from main" << std::endl;
foo();
}
B.cpp
:#include <iostream>
void foo()
{
std::cout << "some text from foo" << std::endl;
}
The important thing to add is project has "Disable Language Extension" set to Yes (/Za). Without this setting, it is bulding properly.
The output is a long list of following errors:
1>B.obj : error LNK2005: "public: static bool const std::numeric_limits<short>::is_signed" (?is_signed@?$numeric_limits@F@std@@2_NB) already defined in A.obj
1>B.obj : error LNK2005: "public: static int const std::numeric_limits<short>::digits" (?digits@?$numeric_limits@F@std@@2HB) already defined in A.obj
1>B.obj : error LNK2005: "public: static int const std::numeric_limits<short>::digits10" (?digits10@?$numeric_limits@F@std@@2HB) already defined in A.obj
1>B.obj : error LNK2005: "public: static bool const std::numeric_limits<unsigned short>::is_signed" (?is_signed@?$numeric_limits@G@std@@2_NB) already defined in A.obj
1>B.obj : error LNK2005: "public: static int const std::numeric_limits<unsigned short>::digits" (?digits@?$numeric_limits@G@std@@2HB) already defined in A.obj
1>B.obj : error LNK2005: "public: static int const std::numeric_limits<unsigned short>::digits10" (?digits10@?$numeric_limits@G@std@@2HB) already defined in A.obj
1>B.obj : error LNK2005: "public: static bool const std::numeric_limits<char16_t>::is_signed" (?is_signed@?$numeric_limits@_S@std@@2_NB) already defined in A.obj
1>B.obj : error LNK2005: "public: static int const std::numeric_limits<char16_t>::digits" (?digits@?$numeric_limits@_S@std@@2HB) already defined in A.obj
...
This seems to indicate, that VS implementation of <iostream>
header breaks One Definition Rule in some nasty way. Is it right, or am I missing something obvious?
I had the same problem compiling the Apache Xerces3 C++ code. The solution was already mentioned by the comment from Stein. You will need an update for the Visual Studio. Version 14.0.2541.03 Update 3 worked, where my older version 14.0.24720.00 Update 1 produced the error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With