B
baileyxia
Hi, all
I am learning how to import c code in python.
Here is my simple code foo.c:
=====================
#include <Python.h>
void bar()
{
printf("Hello! C wrap!");
}
static PyObject *foo_bar(PyObject *self, PyObject *args) {
/* Do something interesting here. */
bar();
Py_RETURN_NONE;
}
static PyMethodDef foo_methods[] = {
{ "bar", (PyCFunction)foo_bar, METH_NOARGS, NULL },
{ NULL, NULL, 0, NULL }
};
PyMODINIT_FUNC initfoo() {
Py_InitModule3("foo", foo_methods, "My first extension module.");
}
=====================
I use gcc to compile the foo.c:
gcc -shared -I/usr/local/python/2.4.2/include/python2.4 -fPIC foo.c -o
foo.so
Problem is:
I can import foo on linux 64-bit platform if I also run gcc on linux
64-bit platform.
But I can not import foo on linux 64-bit platform if I run gcc on linux
32-bit platform.
Here is the error messege:
=====================
traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: ./foo.so: cannot open shared object file: No such file or
directory
=====================
I can not figure out what cause this problem. wrong gcc option? wrong
python code?
I am learning how to import c code in python.
Here is my simple code foo.c:
=====================
#include <Python.h>
void bar()
{
printf("Hello! C wrap!");
}
static PyObject *foo_bar(PyObject *self, PyObject *args) {
/* Do something interesting here. */
bar();
Py_RETURN_NONE;
}
static PyMethodDef foo_methods[] = {
{ "bar", (PyCFunction)foo_bar, METH_NOARGS, NULL },
{ NULL, NULL, 0, NULL }
};
PyMODINIT_FUNC initfoo() {
Py_InitModule3("foo", foo_methods, "My first extension module.");
}
=====================
I use gcc to compile the foo.c:
gcc -shared -I/usr/local/python/2.4.2/include/python2.4 -fPIC foo.c -o
foo.so
Problem is:
I can import foo on linux 64-bit platform if I also run gcc on linux
64-bit platform.
But I can not import foo on linux 64-bit platform if I run gcc on linux
32-bit platform.
Here is the error messege:
=====================
traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: ./foo.so: cannot open shared object file: No such file or
directory
=====================
I can not figure out what cause this problem. wrong gcc option? wrong
python code?