/EHsc option causes LNK2001 error while creating a MC++ 2003 Class Library
-
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
-
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