SWIG on Mac OS X

From Wiki for iCub and Friends
Jump to: navigation, search

Trying to get the example in $YARP_ROOT/example/swig on Mac OS X Tiger require somes hacks.

Yet to be solved

Well... There was a bus error while running example.py :-( which disappeared when using system original python instead of DarwinPorts one. However the problem itself is worked around, it would be nice to know the reason why it happenend...

The point is that the distutils are able to build a working extention for the Darwin Ports version of Python using SWIG... So the problem seems to be more specificaly linked to the CMake module for SWIG on Mac OS X. I can't provide any solution for now, but anyway for building a Python binding I would consider either of :

  • using Boost::Python
  • using the 'SWIG support in the distutils : beeing a build manager in Python it is portable to any platform on which Python is available -- and if it is not on yours, you are not interested by that anymay ;-)

Below is the stuff about what was tried to make a Python wrapper around YARP using CMake and SWIG on Mac OS X. It finaly worked, but only the the Apple provided old Python Framework which has no useful library :-(


In .../swig/CMakeLists.txt to should add a line in order the Python section looks like :

   SET(CMAKE_SWIG_FLAGS "-Wall;-module;yarp")
   SWIG_ADD_MODULE(yarp python yarp.i)


In the SWIG interface file yarp.i you have to change ... to look like :

// Parse the original header files
// Redefine a few things that SWIG currently chokes on
//%define __LINUX__
%define _YARP2_NETINT32_
// %define NetInt32 int
%typedef int yarp::os::NetInt32;

%define _YARP2_VOCAB_ 1


This is the standard CMake module to find Python. As I'm using DarwinPorts, Pyhon libs are in /opt/local/lib. You need either to edit directly the module file (/opt/local/share/CMake/Modules for me), or copy it to the swig directory and edit this local copy in order it looks like :

  NAMES python24 python2.4
        python23 python2.3


DO NO DO IT !!! In fact there is a mysterious bus error when using DarwinPorts python 2.4 : use the python provided with the system instead (so you don't need this hack, but as it can be useful I don't erasse it...)