C++/CLR managed unit test has linker errors

2019-08-01 10:51发布

问题:

When including any managed class to my managed unit test the compile spits out these errors:

1>UnitTest.obj : error LNK2020: unresolved token (0A000360) "extern "C" int __cdecl _CrtDbgReportW(int,wchar_t const *,int,wchar_t const *,wchar_t const *,...)" (?_CrtDbgReportW@@$$J0YAHHPB_WH00ZZ)
1>UnitTest.obj : error LNK2020: unresolved token (0A000361) "extern "C" int __cdecl _CrtDbgReportW(int,wchar_t const *,int,wchar_t const *,wchar_t const *,...)" (?_CrtDbgReportW@@$$J0YAHHPB_WH00ZZ)
1>UnitTest.obj : error LNK2028: unresolved token (0A0003E6) "extern "C" void __cdecl _invalid_parameter(wchar_t const *,wchar_t const *,wchar_t const *,unsigned int,unsigned int)" (?_invalid_parameter@@$$J0YAXPB_W00II@Z) referenced in function "public: void __thiscall std::_Iterator_base12::_Orphan_me(void)" (?_Orphan_me@_Iterator_base12@std@@$$FQAEXXZ)
1>UnitTest.obj : error LNK2019: unresolved external symbol "extern "C" void __cdecl _invalid_parameter(wchar_t const *,wchar_t const *,wchar_t const *,unsigned int,unsigned int)" (?_invalid_parameter@@$$J0YAXPB_W00II@Z) referenced in function "public: void __thiscall std::_Iterator_base12::_Orphan_me(void)" (?_Orphan_me@_Iterator_base12@std@@$$FQAEXXZ)
1>UnitTest.obj : error LNK2001: unresolved external symbol "extern "C" int __cdecl _CrtDbgReportW(int,wchar_t const *,int,wchar_t const *,wchar_t const *,...)" (?_CrtDbgReportW@@$$J0YAHHPB_WH00ZZ)

I am using a clr project as well as including a managed class. Removing the include allows the test to compile.

回答1:

To solve this issue you must remove

"_DEBUG"

from the test project in

[TestProject] -> Properties -> C/C++ --> Preprocessor --> Preprocessor Definitions

Alternitively you can change

"_DEBUG" to "NDEBUG"