Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Guide to Compilation on Windows x64

Dario Izzo edited this page May 11, 2015 · 28 revisions

Preliminaries

We assume your system has a freshly installed Windows 7. This guide will walk you through the necessary steps to compile and install PyKEP/PyGMO module using minGW 64 bits. The guide was compiled when the v1.2.2 (PyKEP) and v1.1.7 (PyGMO) versions were shipped in May 2015.

  • Install Python from the official pages. This tutorial was tested on versions 3.4.3 and 2.7.9. We assume you will install it for all users on your machine so that the python27.dll and python34.dll will be placed in the C:\Windows\System32 directory. Place the python directory on your root directory so that C:\Python27 or C:\Python34 exist. Make sure to get the 64bit version of Python. The 64bit libraries will appear in C:\Windows\System32, the 32bit libraries will appear in C:\Windows\SysWOW64 (how confusing!!)

  • Install mingw for a 64 bits architecture. We used version 4.9.2. If necessary, select (Installer we used) the following options: x86_64, posix threads, seh exceptions.

  • Append C:\Program Files\mingw-w64\x86_64-4.9.2-posix-seh-rt_v4-rev2\mingw64\bin to the PATH environment variable and check that from a cmd window you can type gcc and get gcc: fatal error: no input file. Check also that you can type gendef and it is found.

  • Install cmake (we accessed it from http://www.cmake.org/download/)

Patch Python pyconfig.h

An include file from Python must be patched original reference in order for mingw64 to work. Open the file c:\Python27\include\pyconfig.h (or c:\Python34\include\pyconfig.h), search for the text #ifdef _WIN64, which in our copy of this file was at line 141, and cut out the following three lines:

#ifdef _WIN64
#define MS_WIN64
#endif

Now, search for the text #ifdef _MSC_VER , which in our copy of this file was at line 107. Paste in the cut-out lines, ABOVE the #ifdef _MSC_VER.

Patch Python.dll

We must generate a mingw-64 compatible version on the python library (only for compilation, not to use or distribute afterwards). Take the installed python library c:\windows\system32\python27.dll or c:\windows\system32\python34.dll and copy it into the folder c:\Python27\libs (c:\Python34\libs). From a command line (and in the folder pythonXX\libs), now type:

gendef pythonXX.dll

you should see a message

[pythonXX.dll] Found PE image

You should now have a non empty file named C:\PythonXX\Libs\pythonXX.def

Rename the file pythonXX.lib to old-pythonXX.lib to make sure it will not be linked in during the process. (there maybe also pythonX.lib in which case rename that too)

Build Boost

  • Download boost source (we used this link). Unzip it and rename the folder into boost, so that C:\boost\INSTALL is a correct path.

        bootstrap.bat mingw
        b2 toolset=gcc link=shared --with-python
        b2 toolset=gcc link=shared --with-system
        b2 toolset=gcc link=shared --with-thread (only for PyGMO)
        b2 toolset=gcc link=shared --with-serialization
        b2 toolset=gcc link=shared --with-date_time (only for PyKEP)
    

at the end of this process, you should have all the requested libraries built in stage/lib. Check that the correct version of boost-python has been built. (i.e. libboost_python3-mgw49-mt-1_58.dll or/and libboost_python-mgw49-mt-1_58.dll)

Build PyKEP/PyGMO

Activate the GUI of CMake and, after having selected the build directory, hit configure. Select the options you want to activate (GSL and NLOPT libraries can be downloaded from the web. We used the static GSL library and the dynamic NLOPT library). Make sure that the python library linked in is the one you patched (you will have to manually type C:/PythonXX/libs/PythonXX.dll in the corresponding CMAKE variable). You can select the python version by changing the CMAKE variable of the python executable. Configure and Generate. Type

mingw32-make
mingw32-make install

Watch in which path the dynamic library, headers and python files are placed and move them accordingly (in particular the pagmo.dll and/or keplerian_toolbox.dll will have to be moved so that windows can find them.

Clone this wiki locally