技術メモ
This project is maintained by kino-3
参考にしたサイト: https://buildersbox.corp-sansan.com/entry/2019/12/09/110000
$ pip install pybind11
sample.cpp
を用意する。
#include <pybind11/pybind11.h>
#include <string>
std::string concat(std::string a, std::string b){
return a + b;
}
PYBIND11_MODULE(sample, m)
{
m.doc() = "sample module";
m.def("concat", &concat, "concatenate two strings");
}
コンパイルして共有ライブラリを作成する。
g++ -O3 -Wall -shared -std=c++11 -fPIC `python3 -m pybind11 --includes` sample.cpp -o sample`python3-config --extension-suffix`
Python から作成したライブラリを利用する。
import sample
sample.concat("hoge", "fuga")