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 を使わずにインストールする必要がある場合は,このページの手順によりインストールを行うことができる.
Windows での Build Tools for Visual Studio 2022 (ビルドツール for Visual Studio 2022) のインストール: 別ページ »で説明している.
次のコマンドを実行
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\")" )
次のコマンドを実行
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 のインストール: 別ページ »で説明している.
【関連する外部ページ】
Git の公式ページ: https://git-scm.com/
【サイト内の関連ページ】
Windows での Visual Studio Community 2022 のインストール: 別ページ »で説明している.なお,Visual Studio には,ビルドツール(Build Tools)が含まれている.
Windows での ビルドツール for Visual Studio 2022 (Build Tools for Visual Studio 2022) のインストール: 別ページ »で説明している.
【関連する外部ページ】
前もって,Boost をインストールするディレクトリを決めておく
このページでは,c:\boost 下にインストールするものとして説明する.
コマンドプロンプトを管理者として実行: 別ページ »で説明
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
エラーメッセージが出ていないこと。
次のコマンドで確認する.ここで確認したことは,のちほど,使用する.
dir "c:\boost\build\include"
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
次のコマンドを実行
powershell -command "[System.Environment]::SetEnvironmentVariable(\"BOOST_DIR\", \"c:\boost\build\", \"Machine\")"
次のコマンドを実行
powershell -command "[System.Environment]::SetEnvironmentVariable(\"BOOST_ROOT\", \"c:\boost\build\", \"Machine\")"
次のコマンドを実行
powershell -command "[System.Environment]::SetEnvironmentVariable(\"Boost_INCLUDE_DIR\", \"C:\boost\build\include\boost-1_83\", \"Machine\")"
作者に感謝します.
#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) << " "); }
cl /EHsc /I "c:\boost\build\include\boost-1_83" hoge.cpp echo 1 2 3 | .\hoge.exe