LoginSignup
6
2

More than 5 years have passed since last update.

Visual Studio 2017でC++ライブラリ「Boost」を入れる方法

Posted at

はじめに

AtCoderで競技プログラミングをする中で最大公約数・最小公倍数を出力したい
場合があります。
C++17にgcdとlcm関数があるのですが、AtcoderはC++14までしか対応していないので
使うことができません・・・
そこで最強ライブラリBoostを導入して、この問題を解決しようという記事です。

使用環境:
Windows10
Visual Studio2017
boost 1_68_0

Boostのダウンロード

以下のURLからBoostの最新バージョンをダウンロードします。
https://www.boost.org/users/download/#live
boost.PNG
Windowsなら一番下をダウンロードすれば問題ないと思います。

Cドライブ直下に解凍!

ビルド

コマンドプロンプトの画面
C:\WINDOWS\system32>cd C:\boost_1_68_0
C:\boost_1_68_0>bootstrap.bat

bootstrap.batでビルドします

ビルドが終わったら

×86
b2.exe toolset=msvc-14.1 link=static runtime-link=static,shared --build-dir=build/x86 address-model=32 -j5 install --includedir=C:\boost_1_68_0\include --libdir=C:\boost_1_68_0\stage\lib\x86
×64
b2.exe toolset=msvc-14.1 link=static runtime-link=static,shared --build-dir=build/x64 address-model=64 -j5 install --includedir=C:\boost_1_68_0\include --libdir=C:\boost_1_68_0\stage\lib\x64

と打ち込みます。

かなり長い時間かかります。

Visual Studioの設定

画面上のプロジェクト➞~のプロパティを選択

C/C++ ➞ 全般 ➞ 追加のインクルードディレクトリに下記を追加

C:\boost_1_68_0\include\boost-1_68

リンカー ➞ 全般 ➞ 追加のライブラリディレクトリに下記を追加

×86
C:\boost_1_68_0\stage\lib\x86
×64
C:\boost_1_68_0\stage\lib\x64

これで準備完了です!

gcdを使ってみよう!

#include <iostream>
#include <numeric>
#include <boost/math/common_factor_rt.hpp>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;

    cout << gcd(n, m) << endl;
}

最大公約数が出てきたら成功です!
やったー!

参考

数学
https://boostjp.github.io/tips/math.html

6
2
2

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
6
2