LoginSignup
0
0

More than 1 year has passed since last update.

cmakeでMPIのパスが見つからないときの対処法

Posted at

CMakeで MPIを利用する際には以下のように書くとライブラリのパスやインクルードパスを設定することができる。

find_package(MPI)

add_executable(hello.out hello.cpp)
target_link_libraries(hello.out PRIVATE ${MPI_LIBRARIES})
target_include_directories(hello.out PRIVATE ${MPI_INCLUDE_PATH})

find_package(MPI)によってMPIがインストールされているパスを検索し、インクルードパスとリンクパスが適切に設定される。

しかし、ある時次のようなエラーに遭遇した。

CMake Error in /home/murase/.../cmake-build-debug/CMakeFiles/CMakeTmp/CMakeLists.txt:
  Imported target "MPI::MPI_C" includes non-existent path

    "/usr/local/Cellar/open-mpi/4.1.1_2/include/openmpi"

  * The path was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and references files it does not
  provide.

パスが見つからないという問題でしばらくハマった。
この原因は実はbrew upgrade open-mpiをしていたことが問題でMPIのインストール先のパスが変わっていた。cmakeはfind_packageで見つけたパスをキャッシュしており、パスの変更がcmakeの設定に反映されていなかったのが原因だった。

対処法としては、buildディレクトリを削除してもう一度cmakeするとうまく動作するようになる。clionの場合は、Tools->CMake->"Reset Cache and Reload Project"で問題が解決する。

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