[vtkusers] vtkMFC as .dll vs static library

Alon Mozes amozes77 at yahoo.com
Thu Feb 5 11:42:49 EST 2009


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/162f03ee/attachment.htm>


More information about the vtkusers mailing list