Skip to content

Taoxuan-168/Auto-bind-Python-from-CC-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Auto bind Python from CC++

一个足够简单易用并且可配置的用于从C/C++代码自动绑定为Python代码并生成whl包的工程

本项目克隆于: https://github.com/Neutree/c_cpp_project_framework 并且编译代码部分与原仓库保持一致

pybind11自动绑定部分参考代码: https://github.com/sipeed/MaixPy/tree/main/components/maix

快速上手

  • 1.克隆本仓库,进入/examples/demo目录 使用python project.py menuconfig进入图形界面配置编译工具链以及是打包whl文件 alt text

其中x86对应为本机编译,arm64对应为MaixCam2编译,RISCV64对应为MaiCam/Pro编译 alt text

  • 2.写一个C/C++函数,以及hpp头文件,需要以whl包为文件名,方便自动识别:
namespace add::test
{
    int add(int a, int b) 
    {
        return a + b;
    }
}

为对应的函数写上@modul注释,后面跟上函数路径:

namespace add::test
{
    /**
     * My function, add two integer.
     * @param a arg a, int type
     * @param b arg b, int type
     * @return int type, will a + b
     * @module add.test.add
     */
    int add(int a, int b);
}

其中第一行为函数介绍,@param为参数介绍,@return为返回值介绍(可空) 如果只需要编译并打包为whl文件则无需修改main.cpp 使用python project build即可开始编译并打包whl文件 编译后安装whl后即可在直接直接调用:

import add
add.test.add(1,1)

注意:

  • 一个头文件代表一个模块名,表示要import的模块,例如add.hpp对应import add,其模块名必须以add开头
  • 直接运行cpp_bind_python.py可以只生成绑定后的cpp文件,添加--doc DOC参数可以自动从注释生成文档

About

一个足够简单易用并且可配置的用于从C/C++代码自动绑定为Python代码并生成whl包的工程

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors