一、实验环境
ubuntu 20.04
python 3.7 的虚拟环境
cmake 3.16.3
g++ 9.3.0
二、编译Pybind 11
1、从https://github.com/pybind/pybind11 上下载源码,并解压。
2、conda 创建虚拟环境pybind,并且安装pytest。
pip install pytest
3、进入Pybind11文件夹
mkdir build
cd build
cmake ..
cmake --build . --config Release
make
这个一般不会遇到问题,编译结束会在/build/tests/文件夹下生成两个pybind11开头 .so结尾的文件
三、测试用例
1、进入Pybind11文件夹
mkdir pf_test
cd pf_test
touch main.cpp
touch calc.py
Touch CMakeLists.txt
mkdir lib
将上述的两个.so文件copy到lib文件夹下
将.so文件改名为lib开头的文件
2、在gedit ~/.bashrc中加入工程文件目录
export PYTHONPATH=/home/sywork/pybind11-master/pf_test:$PATH
保存退出后 执行 source ~/.bashrc
3、在pf_test文件夹中