2016年9月20日 星期二

Using Boost 1.54 on Windows 7 For Visual Studio 2013


Tutorial
http://www.boost.org/doc/libs/1_54_0/more/getting_started/windows.html




Download
http://sourceforge.net/projects/boost/files/boost/1.54.0/boost_1_54_0.7z
File size is 51.3 MB compressed and 373MB uncompressed.

Extract
So that the file structure is in form of C:\Program Files\boost\boost_1_54_0\index.htm

Visual Studio Project
Use Visual Studio 2013 > File > New > Project > Visual Studio C++ > Win32 Console Application > Empty

Setup Include Path
<ProjectName> > Right Click > Properties > C/C++ > General > Additional Include Directories >
C:\Program Files\boost\boost_1_54_0\























Header-only Boost.Lambda Code
#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) << " ");
}














Test
Press F5 to compile and run, enter 1 to return 3







Build Boost
cmd.exe
cd C:\Program Files\boost\boost_1_54_0
bootstrap.bat
./b2.exe toolset=msvc-12.0
Running b2.exe takes very long time from 4:49 PM to 5:18 PM or near 30 minutes on my Intel i5-4440 3.1 Ghz 16GB Windows 7 64 bits. While building, it generates additional 3.2 GB of files mainly in .obj, .lib and .rsp in stage and bin.v2 folders.

Build Version 2
Use VS2013 x64 本机工具命令提示
%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"" amd64
bootstrap.bat
b2.exe toolset=msvc-12.0


Generated Files
In folder \bin.v2\libs, the generated .lib file prefixed with libboost_. The following libraries are generated.
atomic chrono context coroutine date_time exception filesystem graph iostreams locale log math prg_exec_monitor program_options python3 random regex serialization signals system test_exec_monitor thread timer unit_test_framework wave wserialization





Compiled-binary Boost.Regex Code
#include <boost/regex.hpp>
#include <iostream>
#include <string>
int main() {
       std::string line;
       boost::regex pat("^Subject: (Re: |Aw: )*(.*)");
       while (std::cin) {
              std::getline(std::cin, line);
              boost::smatch matches;
              if (boost::regex_match(line, matches, pat))
                     std::cout << matches[2] << std::endl;
       }

}

Auto-Linking
Visual Studio supports auto-linking that while build the above code, the name of library will be detected.
For Debug Win32 project, it searches for 'libboost_regex-vc110-mt-gd-1_54.lib'
For Release Win32 project, it searches for 'libboost_regex-vc110-mt-1_54.lib'
<ProjectName> > Right Click > Linker > Additional Library Directories > C:\Program Files\boost\boost_1_54_0\stage\lib\

Potential Error
Error 1 error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1800' in main.obj D:\public\boostexample\boostexample\libboost_regex-vc110-mt-gd-1_54.lib(instances.obj) boostexample

You need to build it with correct version of toolset for b2.exe in previous steps.


沒有留言:

張貼留言

2023 Promox on Morefine N6000 16GB 512GB

2023 Promox on Morefine N6000 16GB 512GB Software Etcher 100MB (not but can be rufus-4.3.exe 1.4MB) Proxmox VE 7.4 ISO Installer (1st ISO re...