python调用so库 undefind symbol_C语言编写的Python模块加载时提示.so中的函数未找到?...

我尝试通过C语言编写一个Python的模块,但是我的C程序本身又依赖于一个第三方的库(libwiringPi.so),当我在Python源程序中import我生成的库时,会提示函数未定义,这些函数都是那个第三方库里的,我应该怎样编译才能让我编译出的模块可以动态链接那个库?

我也尝试过使用gcc手动编译动态链接库,然后用ctyes,但是报一样的错误;生成模块的C代码和setup.py代码都是基于Python源码包中的demo程序。

我的C程序代码

/* Example of embedding Python in another program */

#include "python2.7/Python.h"

#include

void initdht11(void); /* Forward */

int main(int argc, char **argv)

{

/* Initialize the Python interpreter. Required. */

Py_Initialize();

/* Add a static module */

initdht11();

/* Exit, cleaning up the interpreter */

Py_Exit(0);

return 0;

}

/* A static module */

/* 'self' is not used */

static PyObject *

dht11_foo(PyObject *self, PyObject* args)

{

wiringPiSetup();

return PyInt_FromLong(42L);

}

static PyMethodDef dht11_methods[] = {

{"foo", dht11_foo, METH_NOARGS,

"Return the meaning of everything."},

{NULL, NULL} /* sentinel */

};

void

initdht11(void)

{

PyImport_AddModule("dht11");

Py_InitModule("dht11", dht11_methods);

}

setup.py

from distutils.core import setup, Extension

dht11module = Extension('dht11',

library_dirs = ['/usr/lib'],

include_dirs = ['/usr/include'],

sources = ['math.c'])

setup (name = 'dht11',

version = '1.0',

description = 'This is a demo package',

author = 'Martin v. Loewis',

author_email = 'martin@v.loewis.de',

url = 'https://docs.python.org/extending/building',

long_description = '''

This is really just a demo package.

''',

ext_modules = [dht11module])

错误信息

Traceback (most recent call last):

File "test.py", line 1, in

import dht11

ImportError: /usr/local/lib/python2.7/dist-packages/dht11.so: undefined symbol: wiringPiSetup

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值