Как скомпилировать pybind11?
Всем привет. Учусь использовать pybind11. Нужно скомпилировать код. Код программы:
#include <pybind11/pybind11.h>
namespace py = 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");
}
Устанавливала на linux с помощью этих команд:
apt-get install cmake
pip3 install pytest
git clone https://github.com/pybind/pybind11.git
cd pybind11
mkdir build
cd build
cmake ..
make install
Пытаюсь компилировать командой: c++ -O3 -Wall -shared -std=c++11 -fPIC $(python3 -m pybind11 --includes) example.cpp -o example$(python3-config --extension-suffix)
Но появляется ошибка:
/usr/local/include/pybind11/detail/common.h:124:20: fatal error: Python.h: No such file or directory
compilation terminated.
Сможете объяснять куда и какие пути прописывать в команде компиляции
Ответы (1 шт):
Если открыть документацию по pybind11, можно найти замечание:
If you used Include as a submodule to get the pybind11 source, then use
$(python3-config --includes) -Iextern/pybind11/includeinstead of$(python3 -m pybind11 --includes)in the above compilation, as explained in Building manually.
У Вас есть два способа:
- Сделать клон исходного кода
pybind11с Гитхаба, собрать его на своей машине с помощьюcmake, положитьcpp-файл в директориюpybind11(заметьте, неpybind11/build/) и скомпилировать с помощью
c++ -O3 -Wall -shared -std=c++11 -fPIC $(python3 -m pybind11 --includes) example.cpp -o example$(python3-config --extension-suffix)
- Установить
pybind11из репозитория с помощьюapt install pybind11-devи скомпилироватьcpp-файл в любой директории командой
c++ -O3 -Wall -shared -std=c++11 -fPIC $(python3-config --includes) -Iextern/pybind11/include example.cpp -o example$(python3-config --extension-suffix)