LoginSignup
0
0

More than 1 year has passed since last update.

matplotlib-cppをCMakeでビルドする

Posted at

matplotlib-cppについて

matplotlib-cppはC++でmatplotlibを使用するためのライブラリです。
https://github.com/lava/matplotlib-cpp

このライブラリを使用するためにCMakeでビルドを試みたときに、生じたエラーと解決方法です。

環境 : Ubuntu 22.04

ビルドのためのCMakeLists.txt

前提 : matplotlibcpp.hをCMakeLists.txtと同一フォルダにロード済みとしています。
https://github.com/lava/matplotlib-cpp/blob/master/matplotlibcpp.h

CMakeLists.txtはgithubレポジトリにあるものを参考に記述しました。
https://github.com/lava/matplotlib-cpp/blob/master/CMakeLists.txt

CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
project(lib_test CXX)

include(GNUInstallDirs)
set(PACKAGE_NAME lib_test)

# library target
add_library(lib_test INTERFACE)
find_package(Python3 COMPONENTS Development.Embed REQUIRED)
target_link_libraries(lib_test INTERFACE
    Python3::Python
    Python3::Module
)
find_package(Python3 COMPONENTS NumPy REQURIED)
target_link_libraries(lib_test INTERFACE
    Python3::NumPy
)

add_executable(TestCode TestCode.cpp)
target_link_libraries(TestCode PRIVATE lib_test)
set_target_properties(TestCode PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")

エラー

cmakeを実行すると、次のエラーが発生しました。

CMake Error at /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find Python3 (missing: Python3_INCLUDE_DIRS Development.Embed)
  (found version "3.10.4")

原因と解決

python3-devがインストールされていなかったことが原因でした。

次のコマンドでpython3-devをインストールして、再度 cmakeを実行すると無事にビルドできました。

sudo apt-get install python3-dev
0
0
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
0
0