【问题标题】:python calling external C program in solarispython在solaris中调用外部C程序
【发布时间】:2013-03-14 13:34:54
【问题描述】:

我正在尝试调用外部 C 程序。相同的代码已经可以在 linux 和 windows 上运行,但不能在 solaris 上运行。
有人可以看看吗?
原始示例取自http://csl.name/C-functions-from-Python/
C 代码 (myModule.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

在 MinGW 下在 Windows XP 上编译

gcc -Ic:/Python27/include -Lc:/Python27/libs myModule.c -lpython27 -shared -o myModule.pyd

但我无法让它在 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 是 3.4.6 Python 是 2.4.6 x86 机器上的 solaris 10

【问题讨论】:

  • 错误信息告诉你发生了什么。它寻找 libgcc_s.so.1 并找不到它。

标签: python c solaris-10


【解决方案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

【讨论】:

  • 是的 - 这解决了我的问题。我在 /usr/local/lib 中,而不是在 /usr/lib 中。我从来没有想过它需要在正确的目录中。
猜你喜欢
  • 2012-12-26
  • 1970-01-01
  • 2012-03-08
  • 1970-01-01
  • 1970-01-01
  • 2013-09-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多