I\'m having a new-to-me linker error in a project I\'m working with:
1>MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (801311
The fix for me was to set Configuration Properties -> C/C++ -> Code Generation -> Struct Member Alignment -> 16 Bytes (/Zp16)
Seems like my Visual Studio was in some broken state. I was the only one getting that error. I had no changes. I recheck out the project on the side and it was fixed. Maybe it was a problem with my user files.
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:
/clr
switch which applied to the whole project.cpp
files that actually required the CLR, and manually selected /clr
under C/C++ -> General -> Common Language RunTime Support
.Program Database /Zi
from Program 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.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"
/clr
-enabled files. Specifically, under C/C++ -> Code Generation
, I set Enable Minimal Rebuild
to No (/RM-)
, and Basic Runtime Checks
to Default
. This got rid of a bunch of warnings also.Enable C++ Exceptions
to No
on the clr
-enabled files.Hope this helps!