[vtkusers] vtkMFC as .dll vs static library

David Cole david.cole at kitware.com
Thu Feb 5 12:45:05 EST 2009


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


More information about the vtkusers mailing list