python调用so文件,如何从.so文件导入python模块?

[me@hostname python]$ cat hello_world.cc

#include

#include

#include

namespace {

std::string greet() { return "Helloworld"; }

}

using namespace boost::python;

BOOST_PYTHON_MODULE(hello_world)

{

def("greet",greet);

}

[me@hostnmae python]$ g++ -c -fPIC hello_world.cc -I/path/to/boost/headers -I/path/to/python/headers -o hello_world.o

[me@hostname python]$ g++ -shared -Wl,-soname,libhello_world.so -o libhello_world.so hello_world.o

[me@hostname python]$ python

Python 2.7.1 (r271:86832, Jan 10 2011, 09:46:57)

[GCC 3.4.5 20051201 (Red Hat 3.4.5-2)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import sys

>>> sys.path.append('.')

>>> import hello_world

Traceback (most recent call last):

File "", line 1, in

ImportError: No module named hello_world

>>>

I created the .so file as shown above but I'm not able to import inside python. what am I missing?

解决方案

It must be called hello_world.so, not libhello_world.so.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值