[vtkusers] vtkMFC as .dll vs static library

Alon Mozes amozes77 at yahoo.com
Thu Feb 5 23:33:58 EST 2009


I have carefully cleaned, rebuilt and compiled vtk, itk, and my project using only "MT(d)" references.  I can now compile and link with no errors.  But when I launch the app, it seems to load for a bit and then crashes after complaining of memory leaks.  As it runs through the .dlls its loading, one sticks out as not in the normal system32, but instead is loaded from the side-by-side folder - not sure if this is relevant at all:
 
.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.6001.18000_none_5cdbaa5a083979cc\comctl32.dll'

Whereas all the other load lines look like:
 
.exe': Loaded 'C:\Windows\System32\usp10.dll'
 
Following the loading, it displays:
 
Detected memory leaks!
Dumping objects ->
{37972} normal block at 0x03268BB8, 32 bytes long.
Data: < Failed t> 13 00 00 00 13 00 00 00 46 61 69 6C 65 64 20 74 
{37969} normal block at 0x03268A88, 68 bytes long.
.
.
.
{213} normal block at 0x027CB818, 200 bytes long.
Data: < z | > D8 7A 09 03 CD CD CD CD 80 B9 7C 02 D8 80 09 03 
.\.cpp(54) : {212} normal block at 0x027CB6B0, 296 bytes long.
Data: < g& > CD CD CD CD 00 00 00 00 C0 67 26 03 CD CD CD CD 
Object dump complete.
The program '[85320] .exe: Native' has exited with code 1 (0x1).
 
Is this still related to a linker error?  Does delay loading play a role even though I'm statically linking?  Any tips on figuring it out from here?  For now, I'll try to analyze the examples to see if I can find a difference...
 
Thanks for the help.  One step at a time...
 

--- On Thu, 2/5/09, David Cole <david.cole at kitware.com> wrote:

From: David Cole <david.cole at kitware.com>
Subject: Re: vtkMFC as .dll vs static library
To: "Alon Mozes" <amozes77 at yahoo.com>
Cc: vtkusers at vtk.org
Date: Thursday, February 5, 2009, 9:45 AM


The link errors you are seeing may be because there is an old .obj file still around that references the prior setting. Please do a clean build of *everything* in your whole project with all "MT" flags and static libs. The fact that you are getting a link error referring to msvcrt.lib means there is still something around that was compiled with /MD.


You can use the dumpbin tool from a Visual Studio command prompt:
dumpbin /directives *.lib
to find which .lib files you have built that contain references to msvcrt.lib -- those are the ones that need to be rebuilt with /MT flags to prevent the errors you're seeing.




HTH,
David





On Thu, Feb 5, 2009 at 11:42 AM, Alon Mozes <amozes77 at yahoo.com> wrote:






Hi All,
This had followed a thread ("Compile with Visual Studio 2008") but I think has become different enough...
 
I have an MFC project that I'm trying to upgrade in Visual Studio (from .NET 2003 to 2008) that uses vtk (used to be 5.0.3, now upgrading to 5.2.1).  The default use of MFC in the project is as a .dll but I'm having trouble with that.  In addition, I'd prefer to have it as a static library so the entire .exe is self-contained (no need to install additional dependencies).  Either path, I've run into difficulty.
 
Path 1: as a .dll
I build vtk 5.2.1 using CMake and everything is ok.  I find the vtkMFC.dll as expected in the build/debug/bin dir.  In visual studio, I can compile and link successfully, but when I run, it can't find the .dll.  I've added a dir in the Tools->Options->Projects and Solutions->VC++ Dirs as I've seen on some help pages, but it didn't seem to have any effect.  I've copied the .dll directly into my project's debug folder so it's guaranteed to find it, and it does, but the app crashes (and I'm sure this is not the proper way to have it find the .dll - I'd just like to see the app working).  This seems to be unique to the change of vtkMFC as a .dll as I've had the project running with other include/library files just fine.  Any suggestions?
 
Path 2: as a statically linked library (This is more desirable)
I change CMake settings so it should build vtk as a statically linked library, rather than .dll.  By that I mean, I change all "MD" and "MDd" references to "MT" and "MTd".  The "Use of MFC" setting offers 3 options: "Standard Windows Library", "Use MFC as shared .dll", and "Use MFC as static library".  I verify that in the vtkMFC project the "Use of MFC" setting is "Use MFC as static library" as well as in my project.  vtkMFC seems to successfully build as a .lib.  (Interseting note: in 5.0.3, the "Use of MFC" setting is "6" and I haven't been able to find anywhere what that means).  In my project, I remove any setting of _AFXDLL (and verify it's not set in the vtkMFC project).  The project compiles but has errors when linking.  Seems to be a conflict between libcmt.lib and msvcrt.lib.  It suggests setting /nodefaultlib - which I've tried - but that results in other linker errors saying it can't find the most basic functions.  I'm guessing I
 can't just sweepingly use the /nodefaultlib switch.  Does anyone know which .libs I have to ignore to get vtkMFC to work as a static library in my project?  Has anyone used vtkMFC as a static library?
 
Thanks for all the help.




      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090205/ae0e1bdf/attachment.htm>


More information about the vtkusers mailing list