I already gave examples how to use the library in a Python program (and the examples are also available in the source code repository. Here I want to give the details of compiling the library.
Fortunately, there are two tools which make it very eays to produce a Python extension module from a C++ library: SWIG and the Python distutils. The configuration files libkombilo.i (for SWIG) and setup.py (for the distutils) are in the source code repository.
Linux
With SWIG and the distutils installed (under Debian, both are available with a simple apt-get; note that the distutils are in the python-dev package which may not be installed by default), you can simply do
swig -c++ -python libkombilo.i
to have SWIG do its work. This produces libkombilo_wrap.cxx and libkombilo.py, two "wrapper files" for the methods and variables in libkombilo. The next step,
python setup.py build_ext
then invokes the C++ compiler with all the necessary parameters, and this produces (after lots of warnings which can be ignored) a file _libkombilo.so which you just have to copy
cp build/lib.linux-i686-2.4/_libkombilo.so .
from the subdirectory where it is placed to the directory where you started out (where 2.4 is the Python version I used). You should now be able to do "from libkombilo import *" in the Python interpreter and in Python scripts.
Windows
On Windows, things are just as easy as with Linux, provided you have a C++ compiler installed - see libkombiloCPP for a list of freely available compilers, and for some hints on how to set up Dev-C++. I will describe how to proceed with Dev-C++ - I am quite sure that things work almost the same with other compilers. Detailed feedback would be appreciated.
First, you need to add the folder with the gcc and g++ executables to your PATH environment variable. With Windows 2000, go to Control Panel->System->Advanced->Environment Variables, and add c:\dev-cpp\bin to PATH (replace c:\dev-cpp with the folder where you installed Dev-C++).
Furthermore, you need to install SWIG. For Windows users, there is a zip file which contains (among others) a pre-built executable. To simplify things, you should add the folder in which this exe file lives to your PATH, too.
Now, you can apply SWIG
swig -c++ -python libkombilo.i
in the folder where you put all the libkombilo files. Next, you compile the C++ code with
python setup.py build_ext --compiler=mingw32
There will be warnings (which can safely be ignored), but in the end this should produce a _libkombilo.pyd file which you just have to copy from the build subfolder:
copy build\lib.win32-2.3\_libkombilo.pyd .
(where 2.3 is the Python version I used). Now you should be able to start the Python interpreter and to do a from libkombilo import *.
Mac OS X
Marcel GrĂ¼nauer told me that he managed to set up libkombilo on Mac OS X. Here is an extract of what he wrote:
- Compile and install sqlite 3.3.13
- Install boost using fink.
Then make sure that the compiler finds these libraries (and uses the right ones - there also might be an older version of sqlite floating around which does not understand some of the syntax used in libkombilo) by:
export CPPFLAGS="-I/sw/include -I/usr/local/include" export LDFLAGS="-L/sw/lib -L/usr/local/lib"
and apply swig and compile the C++ files:
$ swig -c++ -python libkombilo.i $ python setup.py build_ext $ cp build/lib.darwin-8.8.1-i386-2.4/_libkombilo.so .
Now you should be able to from libkombilo import * in a python interpreter.
