• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 989
  • Last Modified:

C++ .NET DLL base class problem ???

Hi guys ...

I'm using visual C++ .net 2003 and am having linker problems when building the following managed class library (DLL) project :

using namespace System;
namespace Common
{
   public __gc class Base
   {
      public:
         Base(void){}
         ~Base(void){}
   };

   public __gc class Derived : public Base
   {
      public:
         Derived(void){}
   };
}

It compiles successfully, but I get the following linker error :
TestFile error LNK2001: unresolved external symbol "void __cdecl __CxxCallUnwindDtor(void (__thiscall*)(void *),void *)" (?__CxxCallUnwindDtor@@$$J0YAXP6EXPAX@Z0@Z)

The problem can be solved by commenting out the base destructor. However this is not a real solution ... as the base destructor will have some necessity in my project.

Anybody have any ideas why this happens ... and any possible workarounds would be much appreciated ?

Other postings of the same question include :
http://www.mcse.ms/archive108-2004-3-441092.html
http://www.mcse.ms/archive108-2004-3-337904.html
http://www.dotnet247.com/247reference/msgs/40/200176.aspx

¬STeve
0
steve_hsk
Asked:
steve_hsk
  • 3
  • 2
1 Solution
 
drichardsCommented:
Here's a solution someone posted:

>>I have also encountered this problem. In order to compile
>> succesfully you have to link msvcrt.lib with ur class lib.

I did not have any issues compiling and linking a class library with your code.  I checked and I already was linking with msvcrtd.lib (it was a debug build) for other reasons.  I removed msvcrtd.lib from my settings and got your problem along with the others which originally caused me to link with msvcrt.
0
 
drichardsCommented:
Just in case you need instructions:  go to the project properties Linker Input page and add msvcrtd.lib in debug configuration "Additional Dependencies".  Add msvcrt.lib to release configuration settings.  Make sure this matches the C\C++ Code Generation "Runtime Library" setting.   msvcrt(d) goes with "Multi-threaded Debug Dll (/MDd)".  If you choose other settings, I believe you will have to change the lib.  Here's a link to the docs for the runtime library compiler switch:

   http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_.2f.md.2c_2f.ml.2c_2f.mt.2c_2f.ld.asp
0
 
steve_hskAuthor Commented:
Thanks for this solution ... it works as stated :-)

If you could fill me in on 2 things I'd greatly appreciate it :-
(1) I'm curious as to why msvcrt.lib wasn't included as part of my project settings by default, and what this library is used for (MS VC++ Run time or MS v? Common Run Time ? What do MS say about this lib ?
(2) Which search engine and website did you find the solution ?

Many thanks,
¬STeve
0
 
drichardsCommented:
(1) I can't say for sure since I haven't found it documented anywhere, but I would guess it's because the runtime is not needed with a pure managed project and so it is not included by default.  Only when you use runtime functions (printf, etc.) do you need the runtime.    It appears that adding a destructor introduces unmanaged code and you need the runtime to handle the destructor code.  You do not need the derived class to have the problem with the destructor.  I tried removing "Derived" from the project and still it had linker errors without msvcrt.

(2) I used Google and searched for 'CxxCallUnwindDtor'.  Here's the ultimate link with the solution - Google found an index page for the message group that had this link.

    http://www.dotnet247.com/247reference/msgs/43/217012.aspx
0
 
steve_hskAuthor Commented:
Good enough :-)

Many thanks !
¬Steve
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now