回答編集履歴
1
修正
answer
CHANGED
@@ -2,4 +2,38 @@
|
|
2
2
|
「pybind11」または「Boost.python」を使う方法が有名です。
|
3
3
|
ぐぐると、解説記事がでてきます。
|
4
4
|
|
5
|
-
[[python高速化]pybind11によるc++組み込み - Qiita](https://qiita.com/exy81/items/e309df7e33d4ff20a91a)
|
5
|
+
[[python高速化]pybind11によるc++組み込み - Qiita](https://qiita.com/exy81/items/e309df7e33d4ff20a91a)
|
6
|
+
|
7
|
+
## 追記
|
8
|
+
|
9
|
+
pybind11 を試してみました。
|
10
|
+
|
11
|
+
[試したコード](https://github.com/nekobean/snippets/tree/master/301193)
|
12
|
+
|
13
|
+
上記の pybind11 を使ったプロジェクトを作成するための CMakeLists.txt を用意したので、これを参考に関数等を変えてみてください。
|
14
|
+
|
15
|
+
> CMake Error at CMakeLists.txt:8 (pybind11_add_module):
|
16
|
+
> Unknown CMake command "pybind11_add_module".
|
17
|
+
> どうすれば宜しいのでしょうか?
|
18
|
+
|
19
|
+
pybind11 がダウンロードされていない、または適切な場所に配置されておらず参照できない状態かと思います。
|
20
|
+
CMake3.14以上であれば、`FetchContent` を使えば簡単に利用できるようになるので、以下の CMakeLists.txt を参考にしてみてください。
|
21
|
+
|
22
|
+
```
|
23
|
+
cmake_minimum_required(VERSION 3.1.4)
|
24
|
+
project(sample VERSION 0.1.0)
|
25
|
+
|
26
|
+
set(CMAKE_CXX_STANDARD 11)
|
27
|
+
|
28
|
+
# PyBind11 を取得
|
29
|
+
include(FetchContent)
|
30
|
+
FetchContent_Declare(
|
31
|
+
pybind11
|
32
|
+
GIT_REPOSITORY https://github.com/pybind/pybind11
|
33
|
+
GIT_TAG v2.6.0
|
34
|
+
)
|
35
|
+
FetchContent_MakeAvailable(pybind11)
|
36
|
+
|
37
|
+
# pybind11_add_module(モジュール名, a.cpp b.cpp ...)
|
38
|
+
pybind11_add_module(sample main.cpp)
|
39
|
+
```
|