Home - Forums - Documentation - Gallery - Bugs


Compiling Python bindings with MSVC

What you need

This tutorial explains you, how you can build cspython, _cspace, and CEL blpython plugins with MSVC. First, I assume, you successfully compiled CS (and optionally CEL). You can find the complete guide to do this in the manual. Get python packages from the official site, and download a Windows binary package. Install it. Finally, download the correct cs_pyth.cpp from here. Extract the zip file, and copy int your CS/plugins/cscript/csypthon directory. Yes, rewrite the original file. Preparation finished.

Setting up MSVC IDE

1. Run MSVC IDE.

2. Go to the Tools->Options->Projects and Solutions->VC++ Directories Select Include files above. Click to New Line icon, and type or select your Python"2X/Include directory.

3. Select Library files Click to New Line icon, and type or select your Python"2X/libs directory.

From now MSVC will find Python related headers and directories.

Adding projects to CS solution

There are VC projects for cspython and _cspace.pyd shipped with Crystal Space; however, they're not contained in the default solutions since Python may not be present on the user's machine, and the default solutions shouldn't produce build errors.

Open up the Crystal Space solution you normally use.

Right click on the Solution item and choose Add->Existing Project....

Navigate to the directory with the Crystal Space Visual C++ projects for your version of VC (e.g. mk/msvc8). Add the libcrystalspace_python project. Repeat for plgcspython and plg_cspace.

Once they have been added, the dependencies must be set correctly. Right click plg_cspace, choose Project Dependencies.... Tick libcrystalspace and libcrystalspace_python in the Depends On list. Repeat for plg_cspace.

If you now hit F7 to build the solution, the three projects added should be built, with the Python module (_cspace.pyd) and the Python CS plugin (cspython.dll) as the result.

Creating _cspace.pyd

When you want to write CS applications with Python, you need to compile _cspace.pyd. This is easy. You need to compile:

in one project. All project settings are the same, like in the previous, but you don't need any rc file. Additional settings are here: manual. When you copy cspace.pyd in your CS/scripts/python directory, you can run tutorial1,2,3 python scripts. Try them.

You can download my build from here.

| Article | Discussion | View source | History |