2 回答

TA貢獻2003條經(jīng)驗 獲得超2個贊
當您使用 pip 安裝 pybind11 時,您將僅獲得結(jié)果,而不是 pybind 的源(py 文件、包含文件...)。
要運行該示例,您必須檢查源代碼git clone --recursive https://github.com/pybind/cmake_example.git
,然后根據(jù)文檔運行命令。

TA貢獻1776條經(jīng)驗 獲得超12個贊
我正在努力解決同樣的問題。但是,我確實開始將 pybind11 作為子模塊包含在內(nèi)。當嘗試運行“cmake ..”時,我收到以下錯誤代碼:
CMake Error: The source directory "C:/Users/XXXXX/Documents/GitHub/MT" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
(我正在 Windows 機器上工作,文件夾是 GitHub 的一部分,使用 C++ 的 Hello World 程序可以工作。)
從長遠來看,嘗試運行以下最小代碼示例:
#include <pybind11>
int add(int i, int j) {
return i + j;
}
PYBIND11_MODULE(example, m) {
m.doc() = "pybind11 example plugin"; // optional module docstring
m.def("add", &add, "A function which adds two numbers");
}
添加回答
舉報