2013-03-14 26 views
2

我试图调用外部C程序。相同的代码已经可以在linux和windows上运行,但不能在solaris上运行。
有人可以看看吗?
原始的例子是从http://csl.name/C-functions-from-Python/
C代码(mymodule.c的)python在solaris中调用外部C程序

#include <Python.h> 

static PyObject* py_myFunction(PyObject* self, PyObject* args) 
{ 
    char *s = "Hello from C!"; 
    return Py_BuildValue("s", s); 
} 

static PyObject* py_myOtherFunction(PyObject* self, PyObject* args) 
{ 
    double x, y; 
    PyArg_ParseTuple(args, "dd", &x, &y); 
    return Py_BuildValue("d", x*y); 
} 

static PyMethodDef myModule_methods[] = { 
    {"myFunction", py_myFunction, METH_VARARGS}, 
    {"myOtherFunction", py_myOtherFunction, METH_VARARGS}, 
    {NULL, NULL} 
}; 

void initmyModule() 
{ 
    (void) Py_InitModule("myModule", myModule_methods); 
} 

的Python截取调用它

from myModule import * 

print "Result from myFunction:", myFunction() 
print "Result from myOtherFunction(4.0, 5.0):", myOtherFunction(4.0, 5.0) 

编译在Linux(上RHEL测试)

gcc -fPIC -shared -I/usr/include/python2.6 -lpython2.6 -o myModule.so myModule.c 

编译在Windows XP下的MinGW

但我无法让它在solaris上工作。我可以

gcc -fPIC -I/usr/include/python2.4 -L/usr/lib/python2.4 myModule.c -lpython2.4 -shared -o myModule.so 

编译它,但它失败,错误

from myModule import * 
ImportError: ld.so.1: python2.4: fatal: libgcc_s.so.1: open failed: No such file or directory 

有人可以帮我指点迷津?

 
gcc is 3.4.6 
Python is 2.4.6 
solaris 10 on x86 machine

+0

错误消息告诉你发生了什么。它查找libgcc_s.so.1并找不到它。 – 2013-03-14 13:37:29

回答

1

这应该钩你

pfexec rm /usr/lib/libgcc_s.so.1 
pfexec ln -s /opt/ts/gcc/3.4/lib/libgcc_s.so.1 /usr/lib/libgcc_s.so.1 
+0

是的 - 这解决了我的问题。我把它放在/ usr/local/lib中,而不是在/ usr/lib中。它从来没有发生过,它需要在适当的目录中。 – 2013-03-15 07:59:00