[vtkusers] Compile with Visual Studio 2008

David Cole david.cole at kitware.com
Thu Feb 5 11:16:30 EST 2009


The shared/static library choice is very inflexible when using MFC...
For an MFC program to function as expected, you have to use shared or static
MFC libraries, and based on that choice, you must link to the
*corresponding* version of the C runtime libraries. If you use shared MFC
dlls, you must link to the shared dll version of the C runtime libraries. If
you use static MFC, then static C runtime libs...

The same principle then extends to libraries that add to MFC (like VTK does
when you turn on VTK_USE_MFC).

Therefore, if you build VTK with BUILD_SHARED_LIBS ON, you must use shared
MFC libs and link to the shared C runtime libs. (All dlls...)
If you build VTK with BUILD_SHARED_LIBS OFF, you must use static MFC libs
and link to static C runtime libs. (No dlls...)

Additionally, you should use delay loading for all VTK dlls when building an
MFC program that uses VTK dlls so that you do not get false mem leak
reporting at MFC program shutdown time. If you do not use DLL delay loading
and the VTK dlls load first, then their memory allocated at that load time
gets reported as a leak by MFC leak checks, when in fact, the VTK memory is
not leaking, it is just deallocated after the MFC report takes place.

So. VTK 5.2.1 is more flexible and tries to guarantee the correctness of the
result better than 5.0 did... If you want the old static linking to MFC
behavior, just do a full rebuild of VTK with BUILD_SHARED_LIBS OFF and it
should just work.

If you must deal with DLL's, though, I'd recommend copying the VTK dlls into
the same directory with your executable. Mucking around with the PATH is
*always* problematic, no matter how you do it.


HTH,
David


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

> I've rebuilt vtk and also found the vtkMFC Configure.h.  I am able to point
> to the file properly but I'm still struggling to get this fully running...
>
> I can compile and link successfully.  When I run, it can't find the
> vtkMFC.dll.  I change the PATH to point to the build/bin/debug dir (where I
> verified that the .dll exists) via Tools->Options->Projects and
> Solutions->VC++ Directories but it still didn't work.  I'll poke around more
> for VS help, but if there's an obvious answer, it would be appreciated.
>
> Again, this is something I had working with 5.0.3 in an older VS.  I dug
> around to find differences between 5.0.3 and 5.2.1.  One difference is that
> I never had to play with vtkMFC as a .dll.  The vtkMFC project in 5.0.3 had
> an interesting setting for "Use of MFC".  Usually, choices are: Standard
> Windows Libraries, Use MFC as static library, Use MFC as shared library.
> For 5.0.3, this setting is "6".  For 5.2.1, it's set as "Use MFC as shared
> library" (.dll).  This change means I have to change my project also to
> shared (whereas I previously had it as static) - right?  So now it searches
> for the .dll and hence my new troubles. (btw, I copied the .dll into my
> project's debug folder just to see if it works and it finds it but crashes
> soon after - I assume this is probably improper anyway).
>
> Thanks again for the help.
>
> --- On *Wed, 2/4/09, Jim <jiksed at yahoo.com>* wrote:
>
> From: Jim <jiksed at yahoo.com>
> Subject: Re: [vtkusers] Compile with Visual Studio 2008
> To: "David Cole" <david.cole at kitware.com>, "Alon Mozes" <
> amozes77 at yahoo.com>
> Cc: vtkusers at vtk.org
> Date: Wednesday, February 4, 2009, 11:40 AM
>
>
>
> I built VTK 5.2.1 from source with VS 2008 Pro Edition and found
> vtkMFCConfigure.h in the following two folders:
>
> 1) MyBuildDir\GUISupport\MFC\
> 2) CMAKE_INSTALL_PREFIX\include\vtk-5.2\
>
> I configured vtk source in CMake 2.6.2 with both VTK_USE_GUISupport and
> VTK_Use_MFC on. I also had VTK_USE_QT on. I built the binary from VTK.sln by
> building ALL_BUILD project and then building INSTALL project. It was an
> error-free process after commenting out a few lines pointed out by David
> (see below).
>
>
> --- On *Wed, 2/4/09, Alon Mozes <amozes77 at yahoo.com>* wrote:
>
> From: Alon Mozes <amozes77 at yahoo.com>
> Subject: Re: [vtkusers] Compile with Visual Studio 2008
> To: "David Cole" <david.cole at kitware.com>
> Cc: vtkusers at vtk.org
> Date: Wednesday, February 4, 2009, 11:51 AM
>
>    Sorry, I think I had missed both Michael's and Arturo's posts (Should I
> not be expecting an email response or notification of response?  No sign of
> a reply in any junk folder either or even in the digests.  Maybe I'm doing
> something stupid with my multiple email addresses...).  I've found the
> posts online through markmail and will try to address them...
>
> Michael,
> I did build VTK myself.  To be clear: I download the source, use CMake to
> configure it by pointing to the source folder and creating a new build
> folder, and then compile in Visual Studio using the solution file I find in
> that newly populated build directory.  I found no sign of vtkMFCConfigure.h
> anywhere.  From what I understand, I think this is a bug in the vtk
> installation code.
>
> The only trick is that I changed one vtk MFC file to get VTK to compile
> (that winver bug; see the origin of this thread) and then recompiled.  I
> don't imagine that affected this problem.  I am currently not at my dev
> machine, but when I get back, I can try from scratch with downloading vtk,
> configuring in CMake, making the change for that winver bug, and compiling
> in VS and seeing if that file exists (or I guess it should exist immediately
> after the CMake stage?).
>
> Arturo,
> Thanks, that was my original concern.  I'd still like to use VS from start
> to finish if I can since I'm more familiar with it, but I'm glad to know it
> should be a minor change if I can't get this working.
>
> David,
> Long story short, if I understand right, either that file exists and I'm
> not properly pointing to it in my project settings, or it doesn't exist and
> it's a vtk bug.  I'm pretty sure it doesn't exist (I recall searching my
> entire hard drive for it and came up with nothing; I can double check
> tonight).
>
> Thanks again for all the help.
>
> --- On *Wed, 2/4/09, David Cole <david.cole at kitware.com>* wrote:
>
> From: David Cole <david.cole at kitware.com>
> Subject: Re: [vtkusers] Compile with Visual Studio 2008
> To: "Alon Mozes" <amozes77 at yahoo.com>
> Cc: vtkusers at vtk.org, "Jim" <jiksed at yahoo.com>
> Date: Wednesday, February 4, 2009, 9:15 AM
>
> Using CMake is not *required*, it is simply strongly recommended because it
> avoids problems exactly like you are seeing right now.
> All you need to do is add an include directory so that Visual Studio can
> find the file it's looking for.
>
> As Mike Jackson pointed out, though, if you're using an install tree of VTK
> and the file is not actually installed, then you've found a bug in VTK's
> install rules. Please let us know if that's the case, so we can fix it....
>
>
> Thanks,
> David Cole
>
>
> On Wed, Feb 4, 2009 at 11:26 AM, Alon Mozes <amozes77 at yahoo.com> wrote:
>
>>   I've read a bit more about using CMake, and if I understand correctly,
>> we would have to re-run CMake only when we change our project settings, not
>> every time we build as I mistakenly said before.  This is less painful than
>> what I'd thought, but still more difficult than I'd like as project settings
>> do change from time to time and we're now incorporating an extra application
>> on a semi-regular basis.  I'm very accustomed to dealing with the VS project
>> settings format and am a total newbie to the CMake lists.  If you insist
>> that CMake is required to getting the project to work, I will invest the
>> effort.  Otherwise, I would prefer to simply tweak what was an already
>> perfectly functioning project.
>>
>> Thanks for the advice.
>>
>> --- On *Wed, 2/4/09, David Cole <david.cole at kitware.com>* wrote:
>>
>> From: David Cole <david.cole at kitware.com>
>> Subject: Re: [vtkusers] Compile with Visual Studio 2008
>> To: "Alon Mozes" <amozes77 at yahoo.com>
>> Cc: vtkusers at vtk.org, "Jim" <jiksed at yahoo.com>
>> Date: Wednesday, February 4, 2009, 3:45 AM
>>
>>   Are you using CMake to build your project?
>>
>> The file vtkMFCConfigure.h is in your VTK build tree. If you are using
>> CMake to build your project with find_package(VTK) and
>> include(${VTK_USE_FILE}) then it should just work....
>>
>> If you're not using CMake, I would recommend using it for your VTK
>> dependent projects. It's much easier. It's probably just a matter of adding
>> extra include directories for non-CMake-based projects.
>>
>>
>> HTH,
>> David
>>
>>
>> On Tue, Feb 3, 2009 at 9:15 PM, Alon Mozes <amozes77 at yahoo.com> wrote:
>>
>>>   Maybe I spoke too soon...
>>>
>>> I'm able to compile VTK now without complaints about MFC.  However, now I
>>> try to compile my application and I get an error:
>>>
>>> 1>C:\Program Files\Vtk-5.2.1-src\GUISupport\MFC\vtkMFCWindow.h(24) :
>>> fatal error C1083: Cannot open include file: 'vtkMFCConfigure.h': No such
>>> file or directory
>>>   I include vtkMFCWindow.h in one of my own project header files, and
>>> that in turn includes vtkMFCConfigure.h, but I can't find that file anywhere
>>> (I do find a vtkMFCConfigure.h.in <http://vtkmfcconfigure.h.in/> in the
>>> vtk source folder).  I am using VTK 5.2.1.  I checked the previous version I
>>> was using - VTK 5.0.3 - and the vtkMFCWindow.h file doesn't include
>>> vtkMFCConfigure.h.  Instead, it includes vtkConfigure.h, so this seems to be
>>> a new change.  Any idea what I'm doing wrong?  I notice there's an
>>> MFC project setting for compiling using Standard Windows, MFC in a shared
>>> dll, and MFC in a static library.  This setting is available for both the
>>> VTK ALL_BUILD project as well as my own.  I've tried using standard windows
>>> and static library with both with no luck.  Maybe this setting matters
>>> somehow?
>>>
>>> Any help would be greatly appreciated.  Thanks.
>>>
>>>
>>> --- On *Mon, 2/2/09, David Cole <david.cole at kitware.com>* wrote:
>>>
>>> From: David Cole <david.cole at kitware.com>
>>> Subject: Re: [vtkusers] Compile with Visual Studio 2008
>>> To: "Alon Mozes" <amozes77 at yahoo.com>
>>> Cc: vtkusers at vtk.org, "Jim" <jiksed at yahoo.com>
>>> Date: Monday, February 2, 2009, 4:28 AM
>>>
>>>   Did you not see my response to this thread the other day....?
>>>
>>>
>>>   The first three lines of vtkMFCWindow.cpp are the culprit. They read:
>>>   #ifndef WINVER    // Allow use of features specific to Windows 95 and
>>> Windows NT 4 or later.
>>>   #define WINVER 0x0400
>>>   #endif
>>>
>>>   Remove them or comment them out and it should work ok with VS2008.
>>>
>>>   Sorry for the inconvenience....
>>>
>>>
>>> HTH,
>>> David
>>>
>>>
>>>
>>>
>>> On Sun, Feb 1, 2009 at 11:27 PM, Alon Mozes <amozes77 at yahoo.com> wrote:
>>>
>>>>   Not sure why I had to disable video for windows.  I just know that I
>>>> compiled and many errors seems to come from a conflict there (with the vtk
>>>> rendering lib if I remember correctly).  I got rid of that and still have
>>>> one problem with the MFC lib which I know I need.  Anyone out there compile
>>>> VTK with Visual Studio 2008 while keeping the MFC flag?  Is this a problem
>>>> with my Windows settings somehow?  My Visual Studio settings?  Or VTK?
>>>>
>>>> Thanks,
>>>> Alon
>>>>
>>>> --- On *Thu, 1/29/09, Jim <jiksed at yahoo.com>* wrote:
>>>>
>>>> From: Jim <jiksed at yahoo.com>
>>>> Subject: Re: [vtkusers] Compile with Visual Studio 2008
>>>> To: "Alon Mozes" <amozes77 at yahoo.com>, vtkusers at vtk.org
>>>> Date: Thursday, January 29, 2009, 8:14 AM
>>>>
>>>>
>>>>  I am doing the same thing and got a bunch of errors. I wonder why you
>>>> have to turn off VTK_USE_VIDEO_FOR_WINDOWS? Thank you.
>>>>
>>>>
>>>> *Alon Mozes <amozes77 at yahoo.com>* wrote:
>>>>
>>>>   Hi All,
>>>> I have a great project using VTK/ITK in an older version of Visual
>>>> Studio.  I need to upgrade to the latest version of VS (Visual Studio 2008
>>>> Professional Edition).  I've found that I must recompile VTK/ITK to properly
>>>> do so.  I've started from scratch and installed the latest CMake 2.6 which
>>>> offers an option to use the Visual Studio 2008 compiler and VTK 5.2.1.  For
>>>> the configuration, I turn on VTK_USE_MFC (via VTK_USE_GUISUPPORT) and
>>>> VTK_RENDERING.  Then I compile the ALL_BUILD in Visual Studio and I get
>>>> several errors.  I reconfigured CMake to turn off the
>>>> VTK_USE_VIDEO_FOR_WINDOWS and all but one error goes away.  I'm still stuck
>>>> with the following failure (which seems to be in the vtkMFC package which I
>>>> think is critical for me):
>>>>
>>>> C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\sdkddkver.h(217) :
>>>> fatal error C1189: #error : _WIN32_WINNT settings conflicts with _WIN32_IE
>>>> setting
>>>>
>>>> When I dig a little, I'm taken to the following lines of code:
>>>>
>>>> #if
>>>> ((_WIN32_WINNT < _WIN32_WINNT_WIN2K) && (_WIN32_IE > _WIN32_IE_IE60SP1))
>>>>
>>>> #error _WIN32_WINNT settings conflicts with _WIN32_IE setting
>>>> #endif
>>>>
>>>> Its clearly passing this conditional and triggering this error.  The
>>>> weird thing is that the first part of the conditional should be 0 (the
>>>> values seem to be 0x0600 < 0x0500) so the whole thing should not pass.
>>>> What's going on here?  Any help would be greatly appreciated.
>>>>
>>>> Thanks for the help.
>>>>
>>>>
>>>> _______________________________________________
>>>> This is the private VTK discussion list.
>>>> Please keep messages on-topic. Check the FAQ at:
>>>> http://www.vtk.org/Wiki/VTK_FAQ
>>>> Follow this link to subscribe/unsubscribe:
>>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> This is the private VTK discussion list.
>>>> Please keep messages on-topic. Check the FAQ at:
>>>> http://www.vtk.org/Wiki/VTK_FAQ
>>>> Follow this link to subscribe/unsubscribe:
>>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>>
>>>>
>>>
>>>
>>
>>
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:http://www.vtk.org/mailman/listinfo/vtkusers
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090205/0979202a/attachment.htm>


More information about the vtkusers mailing list