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

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

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

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

目次

関連する外部ページ

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

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

前準備

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

関連する外部ページ

Git のインストール

Git のページ https://git-scm.com/ からダウンロードしてインストール:

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

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

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

  1. コマンドプロンプトを管理者として開き次のコマンドを実行する.
  2. インストール

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

    Windows では,コマンドプロン プトを管理者として実行し, 次のコマンドを実行する.

    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_81」のところは,先ほど確認したインクルードディレクトリに一致させること.

    cl /EHsc /I "c:\boost\build\include\boost-1_81" ^
        "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 を設定

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

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

  7. 次のコマンドを実行
    call powershell -command "[System.Environment]::SetEnvironmentVariable(\"BOOST_DIR\", \"c:\boost\build\", \"Machine\")"
    
  8. Windowsシステム環境変数 BOOST_ROOT に,c:\boost\build を設定

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

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

  9. 次のコマンドを実行
    call powershell -command "[System.Environment]::SetEnvironmentVariable(\"BOOST_ROOT\", \"c:\boost\build\", \"Machine\")"
    

    [image]

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

作者に感謝します.

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_81" hoge.cpp
    echo 1 2 3 | .\hoge.exe