LoginSignup
1
2

More than 5 years have passed since last update.

homebrew経由でインストールしたpybind11をcmakeで使う

Posted at

はじめに

pybind11をgit cloneやpipでインストールした場合のCMakeで使う例は結構見つかるものの、homebrewを使ってインストールした場合の使い方(CMakeLists.txtの書き方)の例が見つからなかったのでメモ。

前提

試した環境は以下。

  • macOS High Sierra 10.13.6
  • Python 3.7.0 (homebrewでインストール済み)
  • CMake 3.12.3 (homebrewでインストール済み)

pybind11のインストール

$ brew install pybind11

2018/10/27時点で2.2.4がインストールされました。

使用例

C++ソースやコンパイルの仕方、作成したモジュールのPythonからの使い方は、pybind11でC++の関数をpythonから使うの内容そのものですので、そちらをご参照ください。

CMakeLists.txt

今回メモしておきたかった内容はここ。

find_packageでpybind11を指定した上で、pybind11_add_moduleを使うだけ。
極めてシンプルです。

CMakeLists.txt
cmake_minimum_required(VERSION 3.0)

project(cppmod)
find_package(pybind11)

pybind11_add_module(cppmod SHARED cppmod.cpp)

参考

pybind11でC++の関数をpythonから使う

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2