This is the mail archive of the gsl-discuss@sourceware.org mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

HowTo: compile the GSL using MSVC C++ Toolkit 2003 on Windows XP or Windows 2000


======
Thanks
======
    First off, let me say thanks to all those who have worked so hard on the GNU Scientific Library (GSL).   I'm
impressed with the attention to quality.  A special thanks to the indefatigable Brian Gough, and to Gerard
Jungman.  I hope this little recipe helps someone a fraction as much as the GSL team has helped me.

==========
Background
==========
    I wanted to use the GSL for some linear algebra, some special functions, and some optimization.  These
instructions are for version 1.7 of the GSL, installed in C:\gsl-1.7.  Happily, even though automake works poorly
at best with MSVC, the GSL does seem to compile just fine using the free compilers from MS.

    I am using the Microsoft compilers and standard libraries for the rest of my code, so I wanted to do the same for
my compiled copy of the GSL.  I downloaded and installed (for free!) the Microsoft Visual C++ ToolKit 2003 from
http://msdn.microsoft.com/visualc/vctoolkit2003/, and installed the Microsoft SDK from
http://www.microsoft.com/msdownload/platformsdk/sdkupdate/, though I am not sure the latter was necessary for the
building a DLL from the GSL, just for building the static COFF library.  That said, I have only used the static
libraries, as I am not sure the DLL ended up with any exports.

    I had installed Cygwin, so I had a decent shell (I use zsh) as well as automake/autoconf/gawk and all the other
unixy tools the GSL build environment expects.  You will need to do the same.

==============
Similiar Work:
==============
    Brian Gough at Network Theory supplies a supported version of the GSL compiled in MSVC.  You can find it at

        http://www.network-theory.co.uk/gsl/

    As I provide no guarantees about the integrity of a build arising from the process delineated here, I suggest
serious users work with Network Theory.

    The GSL may once have contained Visual Studio build environments.  Being a makefile fan, I don't have VS.  The
main advantage to this recipe from my perspective is that I have effective scripted makefile control over compile
flags, such as debug flags, and hence debuggers work well when I need them.

============
Environment:
============
    You need:
        INCLUDE set to C:\Program Files\Microsoft Visual C++ Toolkit 2003\include
        LIB set to C:\Program Files\Microsoft Visual C++ Toolkit 2003\lib

    I did the above in the Control Panel just to make sure the slashes came out OK, and because I needed other things
(like Python modules) to compile properly on other projects.


    In addition, in the shell, I did
        export CC=cl.exe
        export LD=link.exe
        export CFLAGS="/IC:/PROGRA~1/MIFD68~1/include /Disfinite=_finite /nologo /IC:/gsl-1.7 /D__STDC__ /Ox"
                             ^^^^
                             this is the location of the Microsoft SDK.  Not sure it is really needed.
        export CPP="cl -E"

    Note that the definition of __STDC__ in the $CFLAGS is necessary because otherwise the Microsoft <math.h> already
defines "complex" to be "_complex", which causes preprocessor macro problems with the GSL.  Note also the
definition of $LD did not seem to make linking work right in later steps, so I did it more manually (see below).



============
Configuring:
============
    After the above, a plain old ./configure from the shell prompt worked fine.



====================
Modifying makefiles:
====================
    Windows does not have symlinks so one must use cp instead. Note that setting the LN_S environment variable before
running ./configure did not work.  So you have to make this fix more deviously.

        foreach i (**/Makefile) perl -i -pe 's|LN_S = ln -s|LN_S = cp|' $i; end

    The syntax above is zsh syntax.  Equivalents for other shells are an exercise for the user ;-)



=========
Building:
=========
    You might as well start with a plain old "make" but the executables won't come out right in the "siman"
subdirectory.  So, to make sure all the object files get built, do

        foreach i (*(/)) (cd $i && make); end

    The syntax above is zsh syntax.  Equivalents for other shells are an exercise for the user ;-)


========
Linking:
========
    Linking is difficult.  Though some more Makefile-fu could probably work, the following hack was successful. 
First, move aside the Cygwin version of link.exe:

        mv /bin/link.exe /bin/link_cygwin.exe

    Now, make the makefiles capable of listing their relevant object files:

        foreach i (*/Makefile) perl -i~ -pe 's|^(lib.*la_OBJECTS =(.*))$|libobjects=$2\n$1|' /tmp/Makefile $i; end
        foreach i (*/Makefile) echo "include /cygdrive/c/tmp/listobj.mak" | cat >> $i; end

    where the file /cygdrive/c/tmp/listobj.mak simply contains (don't forget that's a tab before @echo)
        borg: $(libobjects)
            @echo $(addprefix $(subdir)/,$(libobjects))

    then, using this capability, build a giant DLL and a giant LIB, with

        (foreach i (*(/)) (cd $i && make borg); end)| xargs link.exe \/DLL \/OUT:gsl.dll
        (foreach i (*(/)) (cd $i && make borg); end)| xargs lib.exe \/OUT:gsl.lib

    and finally, for a fine-grained set of static libraries, you can do

        foreach i (*(/)) echo $i; (cd $i && make borg) |  xargs lib.exe  \/OUT:gsl$i.lib; end

    The syntax above is zsh syntax.  Equivalents for other shells are an exercise for the user ;-)


===================
A useful hyperlink:
===================
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_building_on_the_command_line.3a_.overview.asp



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]