Xk0*_*Sid 5 c c++ python boost
嘿伙计们,我很擅长提升c/c ++库.我下载了boost库并构建了库.我使用boost接口在c ++中创建了一个非常简单的python库(实际上它是文档中给出的示例代码).我把它建成了一个dll文件.在文档中,它读取了这个dll暴露给python,它们只是在python中显示导入函数并包含创建的库.我不明白如何将这个DLL暴露给python并以传统('import')方式加载库.如果你想查看代码,那么这里是:
#include <boost/python.hpp>
char const* greet()
{
return "hello, world";
}
BOOST_PYTHON_MODULE(hello_ext)
{
using namespace boost::python;
def("greet", greet);
}
Run Code Online (Sandbox Code Playgroud)
请帮助我真的想用c/c ++和python构建应用程序.我只想使用hello_ext作为:
>>>import hello_ext
>>>print hello_ext.greet()
Run Code Online (Sandbox Code Playgroud)
谢谢.
我把它构建成一个dll文件。在文档中,它显示该 dll 已暴露给 python,它们仅显示 python 中的导入函数并包含创建的库。我不明白如何将该 dll 暴露给 python 并以传统(“导入”)方式加载其中的库。
您需要将该共享库放入模块搜索路径中。有几种方法可以实现这一目标。
一是:
import sys
sys.path.append("<directory-where-hello_ext-module-resides>")
import hello_ext
Run Code Online (Sandbox Code Playgroud)
您的共享库应该称为hello_ext.dll.
| 归档时间: |
|
| 查看次数: |
1440 次 |
| 最近记录: |