Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. /EHsc option causes LNK2001 error while creating a MC++ 2003 Class Library

/EHsc option causes LNK2001 error while creating a MC++ 2003 Class Library

Scheduled Pinned Locked Moved Managed C++/CLI
csharpdotnetc++visual-studiotesting
2 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    George L Jackson
    wrote on last edited by
    #1

    When compiling and linking a MC++ 2003 class library, the /EHsc compiler option causes a LNK2001 error when a class is derived from a base class containing a destructor! Remove the /EHsc option and the code compiles and links with any problems. Create a MC++.NET 2003 Class Library with the following: // bd.h #pragma once using namespace System; namespace Testing { public __gc class Base { public: Base(void) { Console::WriteLine(S"Base::Ctor"); } ~Base(void) { Console::WriteLine(S"Base::Dtor"); } virtual void FromtheBase(void) { Console::WriteLine(S"Base::FromtheBase"); } }; public __gc class Derived : public Base { public: Derived(void) { Console::WriteLine(S"Derived::Ctor"); } }; } C++ Command Line: /Od /AI "C:\Projects2003\Test\LinkError\Debug" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_WINDLL" /FD /EHsc /MTd /GS /Yu"stdafx.h" /Fp"Debug/bd.pch" /Fo"Debug/" /Fd"Debug/vc70.pdb" /W3 /nologo /c /Zi /clr /TP /FU "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\mscorlib.dll" /FU "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.dll" /FU "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Data.dll" Additional Options: /Zl Linker Command Line: /OUT:"C:\Projects2003\Test\LinkError\Debug\bd.dll" /INCREMENTAL /NOLOGO /DLL /DEBUG /ASSEMBLYDEBUG /PDB:"C:\Projects2003\Test\LinkError\Debug/bd.pdb" /FIXED:No nochkclr.obj mscoree.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib "\Program Files\Microsoft Visual Studio .NET 2003\Sdk\v1.1\Lib\mscoree.lib" Additional options: /noentry Error: bd error LNK2001: unresolved external symbol "void __cdecl __CxxCallUnwindDtor(void (__thiscall*)(void *),void *)" (?__CxxCallUnwindDtor@@$$J0YAXP6EXPAX@Z0@Z) After doing a link with the /FORCE option, I noticed the following in ildasm in the derived class ctor: .method public specialname rtspecialname instance void .ctor() cil managed { // Code size 32 (0x20) .maxstack 2 IL_0000: ldarg.0 IL_0001: call instance void Testing.Base::.ctor() .try { IL_0006: ldstr "Derived::Ctor" IL_000b: call void [mscorlib]System.Console::WriteLine(string) IL_0010: leave.s IL_001f } // end .try fault { IL_0012: ldftn instance void Testing.Base::__dtor() IL_0018: ldarg.0 IL_0019: call void

    L 1 Reply Last reply
    0
    • G George L Jackson

      When compiling and linking a MC++ 2003 class library, the /EHsc compiler option causes a LNK2001 error when a class is derived from a base class containing a destructor! Remove the /EHsc option and the code compiles and links with any problems. Create a MC++.NET 2003 Class Library with the following: // bd.h #pragma once using namespace System; namespace Testing { public __gc class Base { public: Base(void) { Console::WriteLine(S"Base::Ctor"); } ~Base(void) { Console::WriteLine(S"Base::Dtor"); } virtual void FromtheBase(void) { Console::WriteLine(S"Base::FromtheBase"); } }; public __gc class Derived : public Base { public: Derived(void) { Console::WriteLine(S"Derived::Ctor"); } }; } C++ Command Line: /Od /AI "C:\Projects2003\Test\LinkError\Debug" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_WINDLL" /FD /EHsc /MTd /GS /Yu"stdafx.h" /Fp"Debug/bd.pch" /Fo"Debug/" /Fd"Debug/vc70.pdb" /W3 /nologo /c /Zi /clr /TP /FU "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\mscorlib.dll" /FU "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.dll" /FU "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Data.dll" Additional Options: /Zl Linker Command Line: /OUT:"C:\Projects2003\Test\LinkError\Debug\bd.dll" /INCREMENTAL /NOLOGO /DLL /DEBUG /ASSEMBLYDEBUG /PDB:"C:\Projects2003\Test\LinkError\Debug/bd.pdb" /FIXED:No nochkclr.obj mscoree.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib "\Program Files\Microsoft Visual Studio .NET 2003\Sdk\v1.1\Lib\mscoree.lib" Additional options: /noentry Error: bd error LNK2001: unresolved external symbol "void __cdecl __CxxCallUnwindDtor(void (__thiscall*)(void *),void *)" (?__CxxCallUnwindDtor@@$$J0YAXP6EXPAX@Z0@Z) After doing a link with the /FORCE option, I noticed the following in ildasm in the derived class ctor: .method public specialname rtspecialname instance void .ctor() cil managed { // Code size 32 (0x20) .maxstack 2 IL_0000: ldarg.0 IL_0001: call instance void Testing.Base::.ctor() .try { IL_0006: ldstr "Derived::Ctor" IL_000b: call void [mscorlib]System.Console::WriteLine(string) IL_0010: leave.s IL_001f } // end .try fault { IL_0012: ldftn instance void Testing.Base::__dtor() IL_0018: ldarg.0 IL_0019: call void

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Just turn it off for the "managed" files. And keep the rest as you want. Hey leppie! Your "proof" seems brilliant and absurd at the same time. - Vikram Punathambekar 28 Apr '03

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups