[vtkusers] Compilers on Windows XP

Kalle Pahajoki kalpaha at st.jyu.fi
Tue Mar 29 01:26:16 EST 2005


DAVID EDWARD JONES wrote:

>  
> Hello All,
>  
> I have previously used VTK, primarily on IRIX systems.  Now I'm 
> starting to use
>  VTK on a Windows XP platform and I'm very uniformed about available 
> C++ compilers.
>
> There seem to be a lot of alternatives with names like "Visual C++ 
> 6.0", "Visual Studio .NET 2003", etc...
>
> My question is "What should I buy and where can I get it?"

I had the same problem too a little while ago, but for me, purchasing a 
compiler was not an option, so I ended up reviewing the free options. I 
found that for me, MinGW was the best option. So here are my 
experiences, in the hope that someone will find them useful.

1) Borland's free compiler
Easy to set up, works fine, but all the libraries need to be in their 
OMF format (there's something in the VTK faq about this). I used the 
python and Tk libraries and it wasn't too much of a burden to convert 
them to the OMF format, but when I switched to wxPython I figured that I 
would take a look at some other compilers that could use the libraries 
available on a system without any conversion.

2) MinGW
Didn't get it to work, initially.

3) Various free Microsoft offerings
Spent a lot of time tracking down the various pieces required but even 
after fixing many hiccups, the compiling was always bailing out, so I 
went back to MinGW, and with some effort, got it to work.

Here are the steps I had to take to get MinGW to compile VTK.

First you need to download MinGW. Mingw 3.0.0-1 seems to work, whereas
mingw 3.2.0 does not (due to, I think,  it having a newer GCC version)

The right version is available at 
http://prdownloads.sf.net/mingw/MinGW-3.0.0-1.exe?download
For MSYS, I think the version does not matter. Versions of MinGW and 
MSYS can be downloaded from http://www.mingw.org/download.shtml

How to build VTK:
Do the cmakesetup magic. Try to configure. Get error. You have to
rename some files in your build directory, under CMake-directory.
There are dll's that have names like libcm*.
Rename (or copy for good measure) them to have the names cm*
So libcmVTK_WRAP_PYTHON2.dll becomes cmVTK_WRAP_PYTHON2.dll and so on.
Go back and finish the CMakeSetup. Then generate the makefiles.

You need to install MSYS, and launch the build (using the 'make' 
command) from the sh.exe
shell that comes with MSYS since the makefiles depend on some bourne 
shell scripting.

The generated makefiles won't work out of the box.
These flags need to be added to the line that builds the libraries for 
it to work.
-Wl,--out-implib=$@.a -Wl,--export-all-symbols -Wl,--enable-auto-import
The flags I found (IIRC) in the makefiles availalble here:
http://www.dpinson.com/software/vtk/index.php

Here's a script that will fix all the makefiles (uses perl so you need 
to have it in your path):

#! /bin/sh
echo "Fixing makefiles in $PWD"
FILES="`find $PWD -name Makefile`"
for file in $FILES
do
echo "Fixing $file"
perl -pi.bak -e 's/libvtk/vtk/g' $file
perl -pi.bak -e 's/-shared  -o/-shared -Wl,--out-implib=$@.a 
-Wl,--export-all-symbols -Wl,--enable-auto-import -o/' $file
done

The python wrappings (don't know about other languages) won't recognize 
your compiled libraries if they have a prepended lib in their names.
(libvtkRendering.dll instead of vtkRendering.dll) so the script also 
changes the makefiles to talk about vtkXXX instead of libvtkXXX.

I found that I sometimes (can't recall exactly why) I had to re-run the 
script to fix the makefiles. It would be more elegant, if instead of 
fixing the Makefiles after they are created, they would be created 
properly. But as it works with sufficiently little hassle, it's  good 
enough for me.

Kalle Pahajoki



More information about the vtkusers mailing list