Access violation in unmanaged code: Linking managed with unmanaged static libs

P

Pixel.to.life

Hi, Gurus,

I recently attempted to build a .Net forms application, that links
with old style unmanaged C++ static libs.
Of course I had to recompile the static lib projects to link properly
with the managed application.

My questions are two fold:

[1] The managed project uses /clr and /MDd (in debug) options. The
unmanaged project, when set to build with /clr, and /MDd, gives link
errors with the managed project:

1>Linking...
1>dcmdataD.lib(dcfilefo.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (OFConsole): (0x0200007c).
1>dcmdataD.lib(dcfilefo.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (OFGlobal<bool>): (0x020000bd).
1>dcmdataD.lib(dcsequen.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (OFConsole): (0x0200007e).
......

Why?


[2] If I change the unmanaged project to build with no clr option, it
then links fine with the managed application module. However, this
time I get a run time access violation as soon as the first global
variable is declared inside the unmanaged code:

/* ---------- global condition constants ---------- */
Why?

I am very much exhausted with things to try.

Any input will be much appreciated.

Thanks.

Pixel.To.Life
[http://groups.google.com/group/medicalimagingscience]
 
P

Pixel.to.life

Hi, Gurus,

I recently attempted to build a .Net forms application, that links
with old style unmanaged C++ static libs.
Of course I had to recompile the static lib projects to link properly
with the managed application.

My questions are two fold:

[1] The managed project uses /clr and /MDd (in debug) options. The
unmanaged project, when set to build with /clr, and /MDd, gives link
errors with the managed project:

1>Linking...
1>dcmdataD.lib(dcfilefo.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (OFConsole): (0x0200007c).
1>dcmdataD.lib(dcfilefo.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (OFGlobal<bool>): (0x020000bd).
1>dcmdataD.lib(dcsequen.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (OFConsole): (0x0200007e).
.....

Why?

[2] If I change the unmanaged project to build with no clr option, it
then links fine with the managed application module. However, this
time I get a run time access violation as soon as the first global
variable is declared inside the unmanaged code:

/* ---------- global condition constants ---------- */

Why?

I am very much exhausted with things to try.

Any input will be much appreciated.

Thanks.

Pixel.To.Life
[http://groups.google.com/group/medicalimagingscience]

More information:

The application executes fine in a release build configuration. It
just doesnt let me debug in...
 
B

Ben Voigt [C++ MVP]

Pixel.to.life said:
Hi, Gurus,

I recently attempted to build a .Net forms application, that links
with old style unmanaged C++ static libs.
Of course I had to recompile the static lib projects to link properly
with the managed application.

My questions are two fold:

[1] The managed project uses /clr and /MDd (in debug) options. The
unmanaged project, when set to build with /clr, and /MDd, gives link
errors with the managed project:

1>Linking...
1>dcmdataD.lib(dcfilefo.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (OFConsole): (0x0200007c).
1>dcmdataD.lib(dcfilefo.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (OFGlobal<bool>): (0x020000bd).
1>dcmdataD.lib(dcsequen.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (OFConsole): (0x0200007e).
.....

Why?

I would guess that your structure packing settings aren't the same for all
source files.

Never use /Wp, use #pragma pack instead around only the headers/definitions
that require different packing.
[2] If I change the unmanaged project to build with no clr option, it
then links fine with the managed application module. However, this
time I get a run time access violation as soon as the first global
variable is declared inside the unmanaged code:

/* ---------- global condition constants ---------- */
Why?

I am very much exhausted with things to try.

Any input will be much appreciated.

Thanks.

Pixel.To.Life
[http://groups.google.com/group/medicalimagingscience]
 
P

Pixel.to.life

Hi, Gurus,
I recently attempted to build a .Net forms application, that links
with old style unmanaged C++ static libs.
Of course I had to recompile the static lib projects to link properly
with the managed application.
My questions are two fold:
[1] The managed project uses /clr and /MDd (in debug) options. The
unmanaged project, when set to build with /clr, and /MDd, gives link
errors with the managed project:
1>Linking...
1>dcmdataD.lib(dcfilefo.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (OFConsole): (0x0200007c).
1>dcmdataD.lib(dcfilefo.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (OFGlobal<bool>): (0x020000bd).
1>dcmdataD.lib(dcsequen.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (OFConsole): (0x0200007e).
.....

I would guess that your structure packing settings aren't the same for all
source files.

Never use /Wp, use #pragma pack instead around only the headers/definitions
that require different packing.




[2] If I change the unmanaged project to build with no clr option, it
then links fine with the managed application module. However, this
time I get a run time access violation as soon as the first global
variable is declared inside the unmanaged code:
/* ---------- global condition constants ---------- */

I am very much exhausted with things to try.
Any input will be much appreciated.

Pixel.To.Life
[http://groups.google.com/group/medicalimagingscience]- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -

Thanks, ben, but that was not the issue.

I found the fix. Apparently this is a known issue in VC2005 express
edition, so when using a static constructor in unmanaged code with a
managed forms application, the entry point of the managed app should
not be 'main'. Here is the link to the angelic description (I tried,
works like magic:)

http://www.thescripts.com/forum/thread642179.html

Thanks to all anyways, and special thanks to Jeffrey Tan (MSFT) who
made an effort.

Pixel.to.life.

Sorry, but another reason I dont like capitalist society- its markets
more than it perfects.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top