现在的位置: 首页 > 综合 > 正文

使用python访问c++库

2014年11月24日 ⁄ 综合 ⁄ 共 392字 ⁄ 字号 评论关闭

平台:ubuntu 8.10 AMD64 + Python 2.5 + Boost

创建hello.cpp文件:

 

在命令行模式中:

 

$ g++ -O3 hello.cpp -shared -o hello.so -I /usr/include/python2.5 -lboost_python -fPIC

生成hello.so

$ python

>>> import sys
>>> sys.path.append("/path/to/.so/file")
>>> import hello
>>> print hello.greet()
hello, world

抱歉!评论已关闭.