1) Boost 라이브러리 홈페이지: www.boost.org (2012년 2월 24일 최신 버전은 1.48.0)
2) Boost 라이브러리 소스 내려받기: http://sourceforge.net/projects/boost/files/boost/1.49.0/
3) 이 문서 작성에 참고한 자료: Boost getting on Windows
4) 이래는 Boost 라이브러리 홈페에지;에 게시된 글...
Boost provides free peer-reviewed portable C++ source libraries.
We emphasize libraries that work well with the C++ Standard Library. Boost libraries are intended to be widely useful, and usable across a broad spectrum of applications. The Boost license encourages both commercial and non-commercial use.
We aim to establish "existing practice" and provide reference implementations so that Boost libraries are suitable for eventual standardization. Ten Boost libraries are included in the C++ Standards Committee's Library Technical Report (TR1) and in the new C++11 Standard. C++11 also includes several more Boost libraries in addition to those from TR1. More Boost libraries are proposed for TR2.
※ Boost 1.49.0 설치하고 테스트하기
[단계 1] 압축 파일을 적당한 곳에 풀어 놓는다. (여기서는 D:\boost_1_49_0 에 풀에 놓은 것으로 간주한다.)
[단계 2] Visual Studio 2010 의 명령 프롬프트를 열고, Boost 의 주 디렉토리로 간다.
프롬프트> D:
프롬프트> cd \boost_1_49_0
[단계 3] 예제 파일 example.cpp 파일을 컴파일한다.
//
// Compile: cl /EHsc example.cpp -I d:\boost_1_49_0
// Execute: echo 1 2 3 | example
#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 example.cpp -I d:\boost_1_49_0
[단계 4] 생성된 실행 파일 example.exe 파일을 실행한다.
프롬프트> echo 10 20 30 | example
[단계 5] 예제 파일 example2.cpp 파일을 컴파일한다.
// Filename: example2.cpp
//
// Compile: cl /EHsc example2.cpp -I d:\boost_1_49_0 /MD /link /LIBPATH:d:\boost_1_49_0\stage\lib
// Execute: example2 < jayne.txt
#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;
}
}
/*
Execution Result:
Will Success Spoil Rock Hunter?
*/
프롬프트> cl /EHsc example2.cpp -I d:\boost_1_49_0 /link /LIBPATH:d:\boost_1_49_0\lib
라이브러리가 아직 빌드되지 않았으므로 당연히 (라이브러리 없음) 에러가 발생한다.
[단계 6] 일괄파일 bootstrap.bat 파일을 실행한다.
프롬프트> bootstrap
[단계 7] b2.exe 파일을 실행한다.
프롬프트> b2
[단계 8] 시간이 꽤 걸리므로 (볼일을 본 후) 한 두시간 후에 다시 컴에 돌아온다.
[단계 9] 생성된 lib 파일들을 확인한다.
프롬프트> dir stage\lib
[단계 10] 다시 example2.cpp 를 컴파일한다,
프롬프트> cl /EHsc example2.cpp -I d:\boost_1_49_0 /link /LIBPATH:d:\boost_1_49_0\lib
LINK : fatal error LNK1104: 'libboost_regex-vc100-mt-s-1_49.lib' 파일을 열 수 없습니다.
아직도 필요한 라이브러리 libboost_regex-vc100-mt-s-1_49.lib 가 없다는 에러 메시지이다.
[단계 11] 라이브러리 경로를 잘 지정하고 다시 example2.cpp 를 컴파일한다,
프롬프트> cl /EHsc example2.cpp -I d:\boost_1_49_0 /link LIBPATH:d:\boost_1_49_0\stage\lib
LINK : fatal error LNK1104: 'libboost_regex-vc100-mt-s-1_49.lib' 파일을 열 수 없습니다.
그래도 라이브러리 libboost_regex-vc100-mt-s-1_49.lib 가 없다고 한다.
실제로 폴더 d:\boost_1_49_0\stage\lib 를 탐색기로 확인해 보아도 그런 파일은 없다.
[단계 12] 이번에는 옵션 /MD 를 주고 다시 example2.cpp 를 컴파일해 본다,
프롬프트> cl /EHsc example2.cpp -I d:\boost_1_49_0 /MD /link LIBPATH:d:\boost_1_49_0\stage\lib
아주 깨끗하게 컴파일된다. (아래는 컴파일되면서 컨솔에 출력되는 메시지)
/out:example2.exe
/LIBPATH:d:\boost_1_49_0\stage\lib
example2.obj
[단계 13] 실행 파일 example2.exe 을 실행하기 전에 다음 내용의 텍스트 파일을 jayne.txt 라는 이름으로 저장한다.
From: Rita Marlowe
Subject: Will Success Spoil Rock Hunter?
---
See subject.
[단계 14] 실행 파일 example2.exe 를 실행한다.
프롬프트> example2 < jayne.txt
Will Success Spoil Rock Hunter?