金子邦彦研究室インストールWindows の種々のソフトウェア(インストール)Windows で VTK 最新版をソースコードからビルドして、インストールする(Build Tools for Visual Studio を利用)

Windows で VTK 最新版をソースコードからビルドして、インストールする(Build Tools for Visual Studio を利用)

Windows で,VTK 最新版をソースコードからビルドして,インストールする手順をスクリーンショット等で説明する. Build Tools for Visual Studio 2022(ビルドツール for Visual Studio 2022)を使用する.

目次

VTK の利用条件などは、利用者が確認すること。次のWeb ページを活用してください

https://github.com/Kitware/VTK

謝辞

VTK の作者に感謝します

前準備

Build Tools for Visual Studio 2022 (ビルドツール for Visual Studio 2022),Visual Studio 2022 のインストール(Windows 上)

サイト内の関連ページ

関連する外部ページ

Git のインストール(Windows 上)

Gitは,バージョン管理システム.ソースコードの管理や複数人での共同に役立つ.

サイト内の関連ページ

Windows での Git のインストール: 別ページ »で説明している.

関連する外部ページ

Git の公式ページ: https://git-scm.com/

CMake のインストール(Windows 上)

CMake はビルドツールである.

サイト内の関連ページ

Windows での cmake のインストール: 別ページ »で説明している.

関連する外部ページ

CMake の公式ダウンロードページ: https://cmake.org/download/

(オプション)OpenBLAS のインストール

OpenBLAS と連携させたいときは、前もって OpenBLAS をインストールしておく

VTK のインストール(Build Tools for Visual Studio を利用)(Windows 上)

  1. Visual Studio の x64 Native Tools コマンドプロンプトを開く.

    起動は,Windows のメニューで「Visual Studio 20..」の下の「x64 Native Tools コマンドプロンプト (x64 Native Tools Command Prompt)」を選ぶ.「x64」は,64ビット版の意味である.

    「x64 Native Tools コマンドプロンプト (x64 Native Tools Command Prompt)」がないとき:

    C++ ビルドツール (Build Tools) のインストールを行うことで, 「x64 Native Tools コマンドプロンプト (x64 Native Tools Command Prompt)」がインストールされる.その手順は,別ページ »で説明

  2. VTK のインストールディレクトリを削除する
    cd %LOCALAPPDATA%
    rmdir /s /q VTK
    

    [image]
  3. VTK のソースコードをダウンロード
    cd %LOCALAPPDATA%
    git clone --recursive https://github.com/Kitware/VTK
    

    [image]
  4. cmake の実行

    cmake でのオプションについて

    • cmake -G "Visual Studio 17 2022"」

    cmake のオプションの 「Visual Studio 17 2022」のところは, 使用する Visual Studio のバージョンにあわせること. Visual Studio 2022 のときは,「Visual Studio 17 2022」. Visual Studio 2019 のときは,「Visual Studio 17 2022

    cmake の実行手順例は次の通り

    cd %LOCALAPPDATA%
    cd VTK
    rmdir /s /q build
    mkdir build
    cd build
    del CMakeCache.txt
    cmake -G "Visual Studio 17 2022" -A x64 -T host=x64 ^
        -DCMAKE_INSTALL_PREFIX="c:\VTK" ^
    ..
    

    [image]
  5. cmake の実行結果の確認

    ※ 下図のとおりになるとは限らない.うまくいっていない場合は、1つ上の「cmake の実行」のところを、設定を変えてやり直す

    [image]
  6. ソースコードからビルドし、インストールする
    cmake --build. --config RELEASE 
    cmake --build. --config RELEASE --target INSTALL
    
  7. 結果の確認

    エラーメッセージが出ていないことを確認.最後のほうに「0 エラー」のように表示されるのを確認.

    ※ 黄色の警告メッセージは無視しても良い

    [image]
  8. Windowsシステム環境変数 Pathに,c:\VTK\bin追加することにより,パスを通す

    Windows で,コマンドプロンプト管理者として実行

    コマンドプロンプトを管理者として実行: 別ページ »で説明

    次のコマンドを実行

    powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";c:\VTK\bin\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"
    
  9. Windowsシステム環境変数 VTK_DIR に,c:\VTK を設定

    Windows で,コマンドプロンプト管理者として実行

    コマンドプロンプトを管理者として実行: 別ページ »で説明

    次のコマンドを実行

    powershell -command "[System.Environment]::SetEnvironmentVariable(\"VTK_DIR\", \"c:\VTK\", \"Machine\")"