469,282 Members | 2,000 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

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

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 ---------- */
>>exception here>const OFConditionConst ECC_Normal( 0, 0, OF_ok, "Normal");
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]

Jul 20 '07 #1
3 2647
On Jul 20, 12:01 am, "Pixel.to.life" <pixel.to.l...@gmail.comwrote:
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 ---------- */
>exception here>const OFConditionConst ECC_Normal( 0, 0, OF_ok, "Normal");

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...

Jul 20 '07 #2

"Pixel.to.life" <pi***********@gmail.comwrote in message
news:11**********************@m37g2000prh.googlegr oups.com...
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 ---------- */
>>>exception here>const OFConditionConst ECC_Normal( 0, 0, OF_ok,
"Normal");

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]
Jul 21 '07 #3
On Jul 20, 8:10 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
"Pixel.to.life" <pixel.to.l...@gmail.comwrote in message

news:11**********************@m37g2000prh.googlegr oups.com...


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 ---------- */
>>exception here>const OFConditionConst ECC_Normal( 0, 0, OF_ok,
"Normal");
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]- 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.

Jul 23 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by chuck rudolph | last post: by
2 posts views Thread by Jon Slaughter | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.