Solved

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

Posted on 2004-09-06
5
966 Views
Last Modified: 2008-01-09
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
Comment
Question by:steve_hsk
  • 3
  • 2
5 Comments
 
LVL 19

Accepted Solution

by:
drichards earned 250 total points
ID: 11992763
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
 
LVL 19

Expert Comment

by:drichards
ID: 11992795
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
 
LVL 2

Author Comment

by:steve_hsk
ID: 11995875
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
 
LVL 19

Expert Comment

by:drichards
ID: 11996960
(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
 
LVL 2

Author Comment

by:steve_hsk
ID: 11997498
Good enough :-)

Many thanks !
¬Steve
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now