boost 설치 방법을 설명해 보겠습니다. boost library version 1.46.1 및 Microsoft Visual Studio 2005 환경입니다. 


boost.png


boost_1_46_1.zip 파일을 다운받습니다. 저는 D:\Project\Other\boost 폴더(이하 $root라 칭하겠음)에 zip 파일을 다운받아 놓는 것으로 가정합니다.

boost_install_windows_sc1.png


zip 파일을 풀어 놓습니다. zip 파일을 푸는 데도 시간이 좀 걸립니다(몇분). 압축 파일을 풀면 "boost_1_46_1"라는 폴더에 파일들이 해제가 됩니다. 파일들의 위치를 한단계 위로 이동시켜 줍니다.

boost_install_windows_sc2.png


Visual Studio를 띄워서 테스트 코드가 컴파일 및 실행이 되는지를 확인합니다. 우선 boost 관련 path가 Visual Studio에 추가되어 있어야 합니다. Visual Studio - Tools - Options - Projects and Solutions - VC++ Directories - Win32 Platform - Include files에 ($root) path를 추가시켜 줍니다.

boost_install_windows_sc3.png


boost_install_windows_sc4.png


#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) << " ");
}


컴파일 및 실행까지 되면 boost 관련 header 파일 설정이 제대로 된 것입니다.

boost_install_windows_sc5.png


boost는 header 파일(*.hpp)만 있어도 사용이 가능한 모듈이 있고, cpp 파일을 컴파일한 library가 있어야만 작동하는 모듈도 있습니다. library가 필요한 모듈은 아래에 열거되어 있습니다(boost 홈페이지에서 발췌).



boost library를 사용하기 위해서는 제일 처음 관련된 모듈을 컴파일하여 library 파일로 만들어 놓아야 합니다. 몇가지 단계가 있으며 다음과 같은 절차를 진행합니다.


우선 DOS command를 띄워서 ($root) 폴더로 이동한 다음에 "bootstrap.bat"파일을 실행시킵니다.

boost_install_windows_sc6.png


"bootstrap.bat"를 실행하면 Boost.Jam과 관련된 파일(bjam.exe, project-config.jam)이 생성되는 것을 확인할 수 있습니다.

boost_install_windows_sc7.png


"bajm.exe" 파일을 실행시킵니다. 이 작업은 작업 시간이 많이 걸립니다. 커피 한잔 먹고 오거나 응가 한번 갔다 와 주는 센스를... ^^

boost_install_windows_sc8.png


bjam.exe를 실행하면 다음과 같이 "bin.v2" 및 "stage" 폴더가 생깁니다.

boost_install_windows_sc9.png


이중에 ($root)/stage/lib 폴더를 보면 확장자가 lib인 파일들을 볼 수가 있습니다. 아 파일들이 바로 boost를 사용할 때 링크가 되어 져야 할 파일들입니다.

boost_install_windows_sc10.png


해당 library 파일들이 제대로 링크가 되어 지는지를 테스트해 보겠습니다. Visual Studio - Tools - Options - Projects and Solutions - VC++ Directories - Win32 Platform - Library files에 ($root)/stage/lib path를 추가시켜 줍니다.

boost_install_windows_sc11.png


다음 테스트 코드를 가지고 컴파일 및 링크가 제대로 되는지 확인을 합니다.

boost_install_windows_sc12.png


#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;
    }
}


Release 모드에서도 컴파일 & 링크가 제대로 되는지 확인을 합니다.

boost_install_windows_sc13.png


저는 Release Mode에서 컴파일을 할 때에는 Runtime Library를 "Multi-threaded (/MT)"로 합니다. 이는 Visual Studio가 설치되어 있지 않은 곳에서도 관련된 파일의 dependencies가 없어도 실행이 되어야 하기 때문입니다. Visual Studio - Project - Properties - Active(Release) - Configuration Properties - C/C++ - Code Generation - Runtime Library 에서 Multi-threaded (/MT)로 설정합니다.

boost_install_windows_sc14.png


그 다음에 다시 컴파일을 해 봅니다. library 파일이 없다는 link error가 뜨게 됩니다.

boost_install_windows_sc15.png


이는 bajm.exe를 이용해서 library file을 만들 때 해당 Runtime Library와 관련된 lib 파일을 생성하지 않았기 때문입니다. 다시 DOS command로 가서 ($root) 폴더에서 다음과 같은 명령어를 실행시켜 줍니다(이 또한 시간이 오래 걸립니다).


bjam variant=release link=static threading=multi address-model=32 runtime-link=static


boost_install_windows_sc16.png


bjam 실행을 마치면 $root/stage/lib  폴더에 "*-mt-s-*.lib" 파일들이 생성되는 것을 확인할 수 있습니다.

boost_install_windows_sc17.png


테스트 코드를 다시 링크를 해서 제대로 링크가 되는지를 확인해 봅니다.

boost_install_windows_sc18.png


이로써 boost library가 자신의 Windows에 제대로 설치가 되었고, Visual Studio에서 컴파일 및 링크가 제대로 된다는 것을 확인하였습니다.