[Pythonmac-SIG] Writting C extension in Mac os X tiger

Bob Ippolito bob at redivi.com
Thu Oct 27 22:47:14 CEST 2005


On Oct 27, 2005, at 12:37 PM, Jaonary Rabarisoa wrote:

> Hi all,
>
>
> I'm trying to write a C++ function that I can use with python. The
> sample code below works well under windows and linux but not under
> mac os x tiger :
>
>
> #include "Python.h"
>
> static PyObject * mHarrisDetector(PyObject *self, PyObject *args)
> {
>
>      //Parse the args
>      const int N = 5;
>      const float eta = sqrt(2.f);
>      const float sigma_0 = 1.f;
>      const char* img_file;
>
>      int ok = PyArg_ParseTuple(args, "s|ffi", &img_file, &sigma_0,
> &eta,&N);
>
>      printf("%s %f %f %d \n",img_file,sigma_0,eta,N);
>
>      Py_INCREF(Py_None);
>      return Py_None;
> }
>
> static PyMethodDef PyIFFD_methods[] = {
>      {"mHarrisDetector",
>        mHarrisDetector,
>        METH_VARARGS,
>        "mHarrisDetector(image,sigma 0,eta,N) -> Array of Harris  
> Point"},
>
>      {NULL, NULL}
> };
>
> extern "C"
> void initPyIFFD(void)
> {
>      Py_InitModule("PyIFFD", PyIFFD_methods);
> }
>
>
>
> To build this code I created a BDS dynamic library with Xcode.  While
> loading the module I get this error :
>
>
>>>> import PyIFFD
>>>>
> Fatal Python error: Interpreter not initialized (version mismatch?)
> Abort trap
>
>
> So what I've missed ?

You forgot to use distutils to compile it, instead of Xcode.   
Specifically, the problem was that you linked to a different problem  
than you are attempting to use it from, potentially with incorrect  
linker flags.  distutils solves this problem for you because it knows  
which Python to link to and which flags to use by way of the Python  
interpreter you invoked setup.py with.

Use distutils.

-bob



More information about the Pythonmac-SIG mailing list