vendredi 15 juin 2018

C++/CLI & Inconsistent layout information in duplicated types (std._Tree_unchecked_const_iterator)

I have got an issue after using the Platform Toolset v141 in Visual Studio 2017 for Debug compilation.

typedef std::map<int, msclr::gcroot<cli::array<short>^>> MapIntToManaged;

int main(array<System::String ^> ^args)
{
    MapIntToManaged testMap;
    for (auto &it : testMap) {}

    return 0;
}

This results in the linker error

error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std._Tree_unchecked_const_iterator< ?? :: ?? >): (0x02000048).
1>LINK : fatal error LNK1255: link failed because of metadata errors

I found a couple of workarounds to get rid of this error:

  • changing the Platform Toolset back to v140
  • using this syntax instead of the auto iterator:

        for (IntToManagedMap::iterator it = testMap.begin(); it != testMap.end(); ++it) {}    
    
    
  • changing the Runtime Library from Multi-threaded Debug DLL (/MDd) to Multi-threaed DLL (/MD)

I'd like to understand this issue. And I want to use the newest toolset, the new iterator syntax and the Debug runtime DLL.

Aucun commentaire:

Enregistrer un commentaire