Solved

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

Posted on 2004-09-06
5
979 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Parse a URL key value 4 188
Random number generation (what's missing?) 7 96
Calling a DLL from CSharp --  How? 4 70
How to measure sizes and angles in scanned images ? 3 89
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 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