File tree Expand file tree Collapse file tree 4 files changed +44
-0
lines changed Expand file tree Collapse file tree 4 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ /extern
2+ /cmake-build-debug-visual-studio
3+ /.idea
Original file line number Diff line number Diff line change 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+ )
Original file line number Diff line number Diff line change 1+ csdn博客:https://blog.csdn.net/qq_41588285/article/details/138529626?spm=1001.2014.3001.5502
2+ github:https://github.com/HurleyKane/pybind_study
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments