LNK2022 and LNK2034 linker errors with version 10.0 of the CRT

前端 未结 5 2061
我寻月下人不归
我寻月下人不归 2021-01-05 09:34

Sorry to bother anyone with this question, but I\'ve been researching this for hours, with no resolution yet:

I am porting a rather massive application to the 10.0 C

5条回答
  •  离开以前
    2021-01-05 10:03

    Although my solution to this issue does not address why it happens, I'm noting my observations in case anyone else comes across my same scenario.

    I too received similar errors compiling my clr project. My goal was to upgrade my version to 11.0, but retain .NET framework 2.0 as the target. In my case, I saw Lnk2034 and lnk2020 errors (different from the lnk2022 noted above).

    1>MSVCMRTD.lib(locale0_implib.obj) : error LNK2034: metadata inconsistent with COFF symbol table: symbol '?_Facet_Register_m@std@@$$FYAXPAV_Facet_base@1@@Z' (06000068) has inconsistent metadata with (0A000C23) in DirectSystemAccessProxy.obj
    1>LINK : error LNK2034: metadata inconsistent with COFF symbol table: symbol '??3@$$FYAXPAX@Z' (060003CB) has inconsistent metadata with (0A00009D) in MSVCMRTD.lib(locale0_implib.obj)
    ...
    1>myProject.obj : error LNK2020: unresolved token (0A000C23) "void __cdecl std::_Facet_Register_m(class std::_Facet_base *)" (?_Facet_Register_m@std@@$$FYAXPAV_Facet_base@1@@Z)
    1>MSVCMRTD.lib(locale0_implib.obj) : error LNK2020: unresolved token (0A0000C4) "extern "C" void __cdecl free(void *)" (?free@@$$J0YAXPAX@Z)
    ...
    

    Initially, I was following Hans Passat's advice by correcting the use of the native containers in this project. I commented out all instances of those containers to verify that they were indeed the cause of failure.

    During the investigation, I discovered that the following line caused my error:

    std::wstringstream wstream;
    wstream << " Failed to to do something \'" << var << "\'.";
    

    The moment I corrected it to the following, those errors went away.

    std::wstringstream wstream;
    wstream << L" Failed to to do something \'" << var << L"\'."; // Added wide string literal.
    

    No idea why such a line would cause this behaviour, but it did.

    Side Note:

    • Targeting a higher .NET framework (4.0) also worked, but I wanted to stick to target the original .NET framework of 2.0.
    • My project did not have the preprecossor definition: _HAS_ITERATOR_DEBUGGING = 0. To my understanding, compiling _HAS_ITERATOR_DEBUGGING in /clr is no longer supported (See link in Hans Passat's answer)

提交回复
热议问题