Linking error while compiling unmanaged C++ code with /clr

  • Thread starter Thread starter B.
  • Start date Start date
B

B.

We converted VC++ 6.0 to VS 2005 and tried to compile with /clr,
however, we got few linking errors:
MSVCMRTD.lib(mstartup.obj) : error LNK2022: metadata operation failed
(8013118D) : Inconsistent layout information in duplicated types
(tagTEXTMETRICA): (0x02000039).

I knew that other ppl had same problem and solved it by turning Struct
Member Alignment to be default. However, our application need it to be
1 byte. Is there any other way to solve the issue?

Thanks a lot,
B.
 
B. said:
We converted VC++ 6.0 to VS 2005 and tried to compile with /clr,
however, we got few linking errors:
MSVCMRTD.lib(mstartup.obj) : error LNK2022: metadata operation failed
(8013118D) : Inconsistent layout information in duplicated types
(tagTEXTMETRICA): (0x02000039).

I knew that other ppl had same problem and solved it by turning Struct
Member Alignment to be default. However, our application need it to be
1 byte. Is there any other way to solve the issue?

You're apparently changing the structure packing globally, while you need to
change it locally - only for the types that you define.

How are you changing the packing? Using #pragma pack() at the top of your
files is not a good solution as you'll inadvertantly change the packing of
type introduced by headers that aren't themselves wrapped in an appropriate
#pragma pack().

-cd
 
Hi Carl,

Thanks for reply. We set the Struct Member Alignment in C/C++ code
generation tab. And we cannot afford to change it since it is a
complicated product and we don't know what unexpected issues will
happen.
 
B. said:
Hi Carl,

Thanks for reply. We set the Struct Member Alignment in C/C++ code
generation tab. And we cannot afford to change it since it is a
complicated product and we don't know what unexpected issues will
happen.

Well, you're going to have to find out. Changing the global option in the
IDE (which sets the command-line option /Zp1) simply won't work for a
managed project - you're changing the definition of system types that are
eposed by the CRT. This is a so-called "ODR Violation" (ODR = One
Definition Rule). Under VC6, you could get away with many ODR violations
(especially related to type you're not using). Under the CLR, you have no
such liberty.

You need to remove the setting in the IDE and set structure packing with
#pragma pack around the structs that you care about or you'll never get it
to work with the CLR.

-cd
 
Back
Top