pybind11使用学习

 

https://www.jianshu.com/p/9619f8f02891

https://www.cnblogs.com/wildkid1024/p/17488842.html

添加引用,添加库

编写代码,主要动态链接库的名称AxTopo4bim应该和PYBIND11_MODULE(AxTopo4bim, m)中的一致。

#include "stdafx.h"
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>

namespace py = pybind11;


PYBIND11_MODULE(AxTopo4bim, m)
{
	m.doc() = "pybind11 example module";

	// Add bindings here
	m.def("foo", []() {
		return "Hello, World!";
	});

	m.def("foo2", []() {
		return "This is foo2!\n";
	});

	m.def("add", [](int a, int b) {
		return a + b;
	});

	m.def("sub", [](int a, int b) {
		return a - b;
	});

	m.def("mul", [](int a, int b) {
		return a * b;
	});

	m.def("div", [](int a, int b) {
		return static_cast<float>(a) / b;
	});
}

  

posted @ 2024-09-09 15:18  太一吾鱼水  阅读(23)  评论(0)    收藏  举报