This commit is contained in:
ZtRXR 2024-06-16 18:06:49 +08:00
parent 38a355c14c
commit c303d57370
4 changed files with 37 additions and 0 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
build
.vscode
# ---> C++ # ---> C++
# Prerequisites # Prerequisites
*.d *.d

6
CMakeLists.txt Normal file
View File

@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.15)
set(PYBIND11_FINDPYTHON ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
project(test_pybind11 VERSION 1.0 DESCRIPTION "a default project" LANGUAGES CXX)
find_package(pybind11 REQUIRED)
pybind11_add_module(${PROJECT_NAME} main.cpp)

17
main.cpp Normal file
View File

@ -0,0 +1,17 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
int add(int i, int j) {
return i + j;
}
std::vector<int> sort_num(std::vector<int> array){
std::sort(array.begin(),array.end());
return array;
}
PYBIND11_MODULE(test_pybind11, m) {
m.doc() = "pybind11 example plugin"; // optional module docstring
m.def("sort_num",&sort_num,"A function to sort INT numbers");
m.def("add", &add, "A function that adds two numbers");
}

12
make.py Normal file
View File

@ -0,0 +1,12 @@
from pymake import *
(
cmake("3.15")
.set("PYBIND11_FINDPYTHON", on)
.set(cmake_export_compile_commands, on)
.project("test_pybind11")
.find_package("pybind11","REQUIRED")
.pybind11_add_module(var(project_name),"main.cpp")
.write()
)