pybind11在Windows下的使用
转自:https://www.e-learn.cn/content/qita/2452765
1.Pybind11算是目前最方便的Python调用C++的工具了, 介绍一下在vs2019上写Python的扩展的HelloWorld
https://github.com/pybind/pybind11/releases/tag/v2.3.0
这个库只要include就可以了
2. 用vs新建一个空项目

PYBIND11_MODULE(文件名, m) 生成的.pyd文件的文件名必须与函数PYBIND11_MODULE中一致
Pybind非常的简单, 几乎就不用修改C++的代码
#include <pybind11/pybind11.h>
namespace py = pybind11;
int chufa(int a, int b)
{
return a / b;
}
PYBIND11_MODULE(example, m)
{
m.doc() = "....";
m.def("foo", []()
{
return "Hello world!";
});
m.def("chufa", &chufa, "just chufa");
}
4.build 得到pyd文件
在python中直接import就可以了…