金子邦彦研究室インストールWindows の種々のソフトウェア(インストール)Boost 1_83 のインストールとテスト実行(ソースコードを使用)(Windows 上)

Boost 1_83 のインストールとテスト実行(ソースコードを使用)(Windows 上)

Boost は, C++ のライブラリ.

Windows で,Boost 最新版をソースコードからビルドして,インストールする手順を説明する.ビルドには,Build Tools for Visual Studio 2022(ビルドツール for Visual Studio 2022)を使用する.

目次

関連する外部ページ

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

https://www.boost.org/users/license.html

下に書いているように,vcpkg を利用してインストールすることができる. 特に問題がない場合には vcpkg の利用してのインストールを検討しよう. vcpkg使わずにインストールする必要がある場合は,このページの手順によりインストールを行うことができる.

Boost のインストール(vcpkg を利用)(Windows 上)

  1. Git のインストール

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

  2. Build Tools for Visual Studio 2022 (ビルドツール for Visual Studio 2022)のインストール

    Windows での Build Tools for Visual Studio 2022 (ビルドツール for Visual Studio 2022) のインストール: 別ページ »で説明している.

  3. vckpg のインストール

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

    次のコマンドを実行

    if not exist c:\vcpkg (
      cd c:\
      rmdir /s /q vcpkg
      git clone https://github.com/microsoft/vcpkg
      cd c:\vcpkg
      git pull
      .\bootstrap-vcpkg.bat
      .\vcpkg update
      .\vcpkg integrate install  
      powershell -command "[System.Environment]::SetEnvironmentVariable(\"VCPKG_ROOT\", \"c:\vcpkg\", \"Machine\")"
      powershell -command "[System.Environment]::SetEnvironmentVariable(\"VCPKG_DEFAULT_TRIPLET\", \"x64-windows\", \"Machine\")"
      powershell -command "[System.Environment]::SetEnvironmentVariable(\"CMAKE_TOOLCHAIN_FILE\", \"c:/vcpkg/scripts/buildsystems/vcpkg.cmake\", \"Machine\")"
      powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"LIB\", \"Machine\"); $oldpath += \";c:\vcpkg\installed\x64-windows\lib\"; [System.Environment]::SetEnvironmentVariable(\"LIB\", $oldpath, \"Machine\")"
      powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"INCLUDE\", \"Machine\"); $oldpath += \";c:\vcpkg\installed\x64-windows\include\"; [System.Environment]::SetEnvironmentVariable(\"INCLUDE\", $oldpath, \"Machine\")"
      powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";c:\vcpkg\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"
      powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";c:\vcpkg\installed\x64-windows\bin\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"
    )
    
  4. Boost のインストール

    次のコマンドを実行

    c:\vcpkg\vcpkg search boost
    c:\vcpkg\vcpkg install --triplet x64-windows boost
    powershell -command "[System.Environment]::SetEnvironmentVariable(\"BOOST_DIR\", \"C:\vcpkg\installed\x64-windows\", \"Machine\")"
    powershell -command "[System.Environment]::SetEnvironmentVariable(\"BOOST_ROOT\", \"C:\vcpkg\installed\x64-windows\", \"Machine\")"
    powershell -command "[System.Environment]::SetEnvironmentVariable(\"Boost_INCLUDE_DIR\", \"C:\vcpkg\installed\x64-windows\include\", \"Machine\")"
    

前準備

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

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

サイト内の関連ページ

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

関連する外部ページ

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

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

サイト内の関連ページ

関連する外部ページ

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

前もって,Boost をインストールするディレクトリを決めておく

このページでは,c:\boost 下にインストールするものとして説明する.

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

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

  2. インストール

    c:\boost 下にインストールするものとして説明する.

    cd c:\
    rmdir /s /q boost
    git clone --recursive https://github.com/boostorg/boost
    cd boost
    .\bootstrap.bat
    .\b2.exe --prefix=build --build-type=complete toolset=msvc link=static,shared address-model=64 install
    
  3. 終了の確認

    エラーメッセージが出ていないこと。

    [image]
  4. バージョンとインクルードディレクトリの確認

    次のコマンドで確認する.ここで確認したことは,のちほど,使用する.

    dir "c:\boost\build\include"
    

    [image]
  5. テスト実行

    Visual Studio の x64 Native Tools コマンドプロンプト管理者として実行する. 次のコマンドを実行する.

    boost-1_83」のところは,先ほど確認したインクルードディレクトリに一致させること.

    cl /EHsc /I "c:\boost\build\include\boost-1_83" ^
        "c:\boost\libs\geometry\example\01_point_example.cpp" 
    .\01_point_example.exe
    del 01_point_example.exe
    

    [image]
  6. Windowsシステム環境変数 BOOST_DIR に,c:/boost/build を設定

    次のコマンドを実行

    powershell -command "[System.Environment]::SetEnvironmentVariable(\"BOOST_DIR\", \"c:\boost\build\", \"Machine\")"
    
  7. Windowsシステム環境変数 BOOST_ROOT に,c:\boost\build を設定

    次のコマンドを実行

    powershell -command "[System.Environment]::SetEnvironmentVariable(\"BOOST_ROOT\", \"c:\boost\build\", \"Machine\")"
    

    [image]
  8. Windowsシステム環境変数 Boost_INCLUDE_DIR に,C:\boost\build\include\boost-1_83 を設定

    次のコマンドを実行

    powershell -command "[System.Environment]::SetEnvironmentVariable(\"Boost_INCLUDE_DIR\", \"C:\boost\build\include\boost-1_83\", \"Machine\")"
    

サンプルプログラムの紹介

作者に感謝します.

http://www.boost.org/doc/libs/1_62_0/more/getting_started/windows.html#build-a-simple-program-using-boost のものを記載.

#include <stdio.h>
#include<boost/lambda/lambda.hpp>
#include<iostream>
#include<iterator>
#include<algorithm>

int main()
{
	using namespace boost::lambda;
	typedef std::istream_iterator<int> in;

	std::for_each(
		in(std::cin), in(), std::cout << (_1 * 3) << " ");
}
  1. 上のプログラムを hoge.cpp のようなファイル名で保存.(拡張子は .cpp)
  2. 次のコマンドにより,コンパイルして実行
    cl /EHsc /I "c:\boost\build\include\boost-1_83" hoge.cpp
    echo 1 2 3 | .\hoge.exe