CMake + Pybind11安装教程
开发环境:VScode, Centos7,Miniconda
使用源码部署和虚拟环境管理
遇到的问题 在使用CMakeLists.txt配置Pybind11后,无法在文件中引入pybind11,表现为:
fatal error: pybind11/pybind11.h: No such file or directory
和 Python.h: No such file or directory
解决方案:
-
首先从pybind的Github仓库中下载源码,放在项目中
-
通过以下命令进行安装
cd pybind11 cmake -S . -B build cmake --build build -j 8 sudo cmake --install build
-
然后在CMakeLists.txt里面写下命令,找到python解释器,并将路径包括进去,以便于c++编译器查看
set(Python_ROOT_DIR "/home/yourname/miniconda3/envs/ittng") find_package(Python 3.10 COMPONENTS Interpreter Development REQUIRED) find_package(pybind11 REQUIRED) include_directories(${Python_INCLUDE_DIRS})
-
这里的root替换成你想要的root