LoginSignup
32

More than 5 years have passed since last update.

boostの導入(Windows10,Visual Studio 2015)

Last updated at Posted at 2017-04-15

目的

C++の代表的な機能拡張ライブラリの一つであるboostの環境構築について記述します.

環境

  • Windows 10
  • Visual Studio 2015
  • boost 1.63.0

ダウンロード

まず,こちらからboost_1_63_0.zipをダウンロードします.
ダウンロードした位置で構わないので全て展開しておきます.

ビルド

解凍が終わったら,管理者権限でコマンドプロンプトを開きます.
..\boost_1_63_0\boost_1_63_0まで移動して下記バッチファイルを実行します.

$ bootstrap.bat

32/64ビット版それぞれのライブラリファイルを生成するため,下記コマンドにてビルド実行.
Cドライブ直下に,必要な全てのファイルを配置するようにしています.

$ b2.exe toolset=msvc-14.0 link=static runtime-link=static,shared --build-dir=build/x86 address-model=32 -j5 install --includedir=C:\boost_1_63_0\include --libdir=C:\boost_1_63_0\lib\x86
$ b2.exe toolset=msvc-14.0 link=static runtime-link=static,shared --build-dir=build/x64 address-model=64 -j5 install --includedir=C:\boost_1_63_0\include --libdir=C:\boost_1_63_0\lib\x64

インストールオプションの詳細は参考に委ねますが,基本的なオプションは下記にまとめておきます.

boostインストールオプション

  • --toolset:ビルドを実行するツールセットを指定します.
    e.g.) --toolset=msvc-14.0:(VS2015) のコンパイラを使用
  • address-model=N:Nに32または64を指定します.
  • -jN:Nに並列実行させるCPUコア数を指定します.
  • --libdir:本来はインストールしたいライブラリファイルの保存先を設定するオプションですが,インストール先ディレクトリを指定するような使い方をしています.
    OOはソリューションプラットフォームに応じて86か64を入れます.
    e.g.) --libdir=C:\boost_1_63_0\lib\xOO:
  • --includedir:上と同様に,インクルードファイルのインストール先ディレクトリを指定するために使っています.
    e.g.) --includedir=C:\boost_1_63_0\include

Visual Studioにおける設定

  • C/C++の全般タブから追加のインクルードディレクトリに下記を追加.
C:\boost_1_63_0\include\boost-1_63
  • リンカーの全般タブから追加のライブラリディレクトリに下記を追加.
C:\boost_1_63_0\lib\xOO

確認

下記を実行して,導入したboostのバージョンが出力されれば成功です.

#include <iostream>
#include <boost/version.hpp>

int main() {
    std::cout << (BOOST_VERSION / 100000) << "." << (BOOST_VERSION / 100 % 1000) << "." << (BOOST_VERSION % 100) << std::endl;
    getchar();
    return 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
32