13,133
回編集
| 7行目: | 7行目: | ||
== Boostのインストール == | == Boostのインストール == | ||
==== CentOS / SUSE ==== | |||
Boostをビルドするため、依存関係のライブラリをインストールする。<br> | Boostをビルドするため、依存関係のライブラリをインストールする。<br> | ||
sudo zypper install libicu-devel libbz2-devel libzstd-devel | sudo zypper install libicu-devel libbz2-devel libzstd-devel | ||
| 59行目: | 60行目: | ||
* <code>--toolset</code>オプション | * <code>--toolset</code>オプション | ||
*: ビルドに使用するツールセットを指定する。 | *: ビルドに使用するツールセットを指定する。 | ||
<br> | |||
==== Windows ==== | |||
[https://www.boost.org/users/download/ Boostの公式Webサイト]にアクセスして、Boostをダウンロードする。<br> | |||
ダウンロードしたファイルを解凍する。<br> | |||
<br> | |||
解凍したディレクトリに移動して、コマンドプロンプトまたはPowerShellを管理者権限で実行する。<br> | |||
b2.exeファイルを生成するため、バッチファイルを起動する。<br> | |||
bootstrap.bat | |||
<br> | |||
Boostのライブラリファイルを生成する、<br> | |||
32ビットおよび64ビットの両方を生成しても構わない。<br> | |||
# 32ビット向けライブラリを生成する場合 | |||
b2.exe toolset=msvc-14.x link=static runtime-link=static,shared --build-dir=build/x86 address-model=32 -j <CPUのコア数> install --includedir=<Boostのインストールディレクトリ>\include --libdir=<Boostのインストールディレクトリ>\stage\lib\x86 | |||
# 64ビット向けライブラリを生成する場合 | |||
b2.exe toolset=msvc-14.x link=static runtime-link=static,shared --build-dir=build/x64 address-model=64 -j <CPUのコア数> install --includedir=<Boostのインストールディレクトリ>\include --libdir=<Boostのインストールディレクトリ>\stage\lib\x64 | |||
<br> | |||
次に、Visual Studioを起動して、任意のC++のプロジェクトを作成する。<br> | |||
<u>これは、各プロジェクトごとに設定する必要があることに注意する。</u><br> | |||
<br> | |||
[プロジェクト]メインメニュー - [プロパティ]を選択する。<br> | |||
[プロジェクトページ]画面が開くので、画面左にある[C/C++] - [全般] - 画面右にある[追加のインクルードディレクトリ]に、以下の設定を追記する。<br> | |||
<Boostのインストールディレクトリ>\include\boost-<バージョン> | |||
<br> | |||
[プロジェクトページ]画面の画面左にある[リンカー] - [全般] - 画面右にある[追加のライブラリディレクトリ]に、以下の設定を追記する。<br> | |||
# 32ビット向けライブラリの場合 | |||
<Boostのインストールディレクトリ>\stage\lib\x86 | |||
# 64ビット向けライブラリの場合 | |||
<Boostのインストールディレクトリ>\stage\lib\x64 | |||
<br> | |||
Boostライブラリが使用できるかどうかを確認するため、以下に示すサンプルコードをビルドおよび実行する。<br> | |||
<syntaxhighlight lang="c++"> | |||
#include <iostream> | |||
#include <vector> | |||
#include <string> | |||
#include <boost/version.hpp> | |||
#include <boost/property_tree/ptree.hpp> | |||
#include <boost/property_tree/xml_parser.hpp> | |||
#include <boost/foreach.hpp> | |||
struct Boost_Test { | |||
std::string name1; | |||
std::string name2; | |||
}; | |||
int main() | |||
{ | |||
std::cout << "boostバージョン : " << BOOST_VERSION << "\n"; | |||
std::cout << "boostライブラリバージョン : " << BOOST_LIB_VERSION << "\n"; | |||
std::vector<Boost_Test> books; | |||
books.reserve(2); | |||
Boost_Test test; | |||
test.name1 = "BoostTest1"; | |||
test.name2 = "100"; | |||
books.push_back(test); | |||
test.name1 = "BoostTest2"; | |||
test.name2 = "200"; | |||
books.push_back(test); | |||
using boost::property_tree::ptree; | |||
ptree pt; | |||
BOOST_FOREACH(const Boost_Test & data, books) | |||
{ | |||
ptree& child = pt.add("list.data", ""); | |||
child.put("<xmlattr>.name1", data.name1); | |||
child.put("<xmlattr>.name2", data.name2); | |||
} | |||
using namespace boost::property_tree::xml_parser; | |||
const int indent = 2; | |||
write_xml("test.xml", pt, std::locale(), xml_writer_make_settings<std::string>(' ', indent)); | |||
return 0; | |||
} | |||
</syntaxhighlight> | |||
<br> | |||
# 出力例 | |||
boostバージョン:107600 | |||
boostライブラリバージョン:1_76 | |||
<br> | |||
<syntaxhighlight lang="xml"> | |||
# test.xmlファイルの内容 | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<list> | |||
<data name1="BoostTest1" name2="100"/> | |||
<data name1="BoostTest2" name2="200"/> | |||
</list> | |||
</syntaxhighlight> | |||
<br><br> | <br><br> | ||
__FORCETOC__ | __FORCETOC__ | ||
[[カテゴリ:C++]] | [[カテゴリ:CentOS]][[カテゴリ:SUSE]][[カテゴリ:Windows10]][[カテゴリ:C++]] | ||