LNK2022 metadata operation: Inconsistent layout information in duplicated types
Alright, so I solved it! There was another SO question that was actually a big help. It ended up linking to the this article, which had a bit more detail about the problem. Basically it's some issue with the standard library strings getting compiled in both managed and unmanaged code. The solution was to only enable the CLR on files which required it. In detail, here's what I did:
- Removed the
/clr
switch which applied to the whole project - Selected the two
.cpp
files that actually required the CLR, and manually selected/clr
underC/C++ -> General -> Common Language RunTime Support
. - Switched the whole project to
Program Database /Zi
fromProgram Database for Edit and Continue /ZI
. This got rid of warnings, because I think/clr
support appeared to disable incremental linking, and then my native code was throwing warnings because it was trying to use Edit and Continue. - I then got some
ExtensionAttribute
warnings, which I fixed by adding the following switches to my/clr
-enabled files:/clr:nostdlib /AI"%ProgramFiles%\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0"
- In Debug builds, I had to disable a bunch of debug options on the
/clr
-enabled files. Specifically, underC/C++ -> Code Generation
, I setEnable Minimal Rebuild
toNo (/RM-)
, andBasic Runtime Checks
toDefault
. This got rid of a bunch of warnings also. - In Debug and Release builds, set
Enable C++ Exceptions
toNo
on theclr
-enabled files.
Hope this helps!