Linker error LNK2005 when compiling (x64) json-3.10.0.zip with Visual Studio 2019 16.11.1 #2941
Closed
Description
What is the issue you have?
Linker error LNK2005:
unit-regression2.obj : error LNK2005: "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * sax_no_exception::error_string" (?error_string@sax_no_exception@@2PEAV?$basic_string@DU?$char_traits@D@std@@V?$allo
cator@D@2@@std@@EA) already defined in unit-disabled_exceptions.obj [build\json\test\json_unit.vcxproj]
build\json\test\Release\json_unit.exe : fatal error LNK1169: one or more multiply defined symbols found [build\json\test\json_unit.vcxproj]
Can you provide a small but working solution / fix?
Add a namespace in both files json\test\src\unit-disabled_exceptions.cpp
and json\test\src\unit-regression2.cpp
:
namespace
{
class sax_no_exception : public nlohmann::detail::json_sax_dom_parser<json>
{
...
};
std::string* sax_no_exception::error_string = nullptr;
} // namespace
What is the expected behavior?
No link error
And what is the actual behavior instead?
LNK2005 error
Which compiler and operating system are you using?
- Compiler: Visual Studio 2019 16.11.1 Professional
- Operating system: Windows 10 21H1
Which version of the library did you use?
- latest release version 3.10.0 (zip file)
- other release - please state the version: ___
- the
develop
branch
If you experience a compilation error: can you compile and run the unit tests?
- yes
- no - please copy/paste the error message below