Skip to content

Commit 258e7d8

Browse files
committed
initital_datas
0 parents  commit 258e7d8

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/extern
2+
/cmake-build-debug-visual-studio
3+
/.idea

CMakeLists.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
cmake_minimum_required(VERSION 3.28)
2+
project(untitled11)
3+
4+
# 添加子目录 pybind11
5+
add_subdirectory(extern/pybind11)
6+
7+
# 加入cpp文件
8+
pybind11_add_module(example SHARED example.cpp)
9+
10+
# 设置输出文件后缀名为 .pyd
11+
set_target_properties(example PROPERTIES SUFFIX ".pyd")
12+
13+
# 添加包含目录
14+
include_directories(
15+
"E:\\DataBuffer\\hurleykane\\miniconda3\\include"
16+
"pybind11\\include"
17+
)
18+
19+
# 添加库目录
20+
set(PYTHON_LIB_DIR "E:\\DataBuffer\\hurleykane\\miniconda3\\libs")
21+
find_library(PYTHON3_LIB python3 PATHS ${PYTHON_LIB_DIR})
22+
find_library(PYTHON311_LIB python311 PATHS ${PYTHON_LIB_DIR})
23+
link_directories(${PTTHON_LIB_DIR})
24+
25+
# 添加依赖项
26+
target_link_libraries(example PUBLIC
27+
${PYTHON3_LIB}
28+
${PYTHON311_LIB}
29+
)

README

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
csdn博客:https://blog.csdn.net/qq_41588285/article/details/138529626?spm=1001.2014.3001.5502
2+
github:https://github.com/HurleyKane/pybind_study

example.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <pybind11/pybind11.h>
2+
3+
int add(int i, int j) {
4+
return i + j;
5+
}
6+
7+
PYBIND11_MODULE(example, m) {
8+
m.doc() = "pybind11 example plugin"; // optional module docstring
9+
m.def("add", &add, "A function that adds two numbers");
10+
}

0 commit comments

Comments
 (0)