boost 설치 하기

반응형
boost가 정말 잘 만들어진 라이브러리어서 안 쓸 수가 없다.

가장 기본인 boost 설치하는 방법을 설명 하겠다.


나의 환경:
  boost version: 2008.6.26. 현재 1.35.
  site: http://www.boost.org/
  compiler: visual studio 2005.
  os: windows xp


1. boost 사이트로 가서 boost를 down 받는다.
http://www.boost.org/users/download/
boost package와 boost jam이 있는데,
boost package이  boost library이고 boost jam은 boost를 컴파일 해 주는 utility이다.
boost jam은 다운받지 않겠다.

2. boost를 down 받아서 압축을 푼다.
  나는 D:\SDK\boost_1_35_0\ 에 압축을 풀었다.

  boost는 보통은 stl처럼 header에 필요한 기능이 다 있으나,
  thread, regex 등등을 쓰려면 library 형태의 compile이 필요하다.

  일단, include 만으로 프로그래밍이 끝난다면 더이상 설치할 필요는 없다.

3. library 만들기. (boost jam을 이용한 방법)
  이것은 boost에서 권하는 boost jam을 이용하는 방법이다.
  이것이 맘에 들지 않는다면, 4번 항목으로 바로 가길 바란다.

  D:\SDK\boost_1_35_0\tools\jam\src\build.bat 을 실행 시킨다.
  D:\SDK\boost_1_35_0\tools\jam\src\bin.ntx86 에 bjam.exe 이 생겼을 것이다.
  이것이 '1'번 항목에서 언급한 boost jam 이다.
  이것을 D:\SDK\boost_1_35_0에 복사한다.

  bjam 을 사용하는 방법은
  http://www.boost.org/doc/tools/build/doc/html/index.html의 tutorial부분인
  http://www.boost.org/doc/tools/build/doc/html/bbv2/tutorial.html을 보고 쉽게 시작할 수 있다.

  나 같은 경우는
  command 창에서
  D:\SDK\boost_1_35_0\bjam debug link=static
  으로 빌드하였다.
  debug는 release, static은 dynamic으로 바꿀 수 있다.

  이렇게 빌드가 되면, 빌드된 결과물들인 dll이나 lib들은
  D:\SDK\boost_1_35_0\bin.v2\  에 각각 들어가게 된다.

4. library 만들기. (수동으로 프로젝트 만들기)
  '3'번이 맘에 안 든 사람들이 다음과 같이 하면 된다.
  일단 수동으로 visual studio 에서 library용 프로젝트를 만든다.
  D:\SDK\boost_1_35_0\libs 에 있는 디렉토리 중에 자신이 원하는 프로젝트의 소스를 모두 여기에 넣는다.
  그리고 빌드.

5. boost::regex를 이용한 샘플을 exe로 만들어 보기로 하자.
  1) boost jam을 이용하여 lib를 만들어 놓은 경우.
compile option:
  추가 include 디렉토리: D:\SDK\boost_1_35_0
  Runtime Library: Multi-threaded Debug DLL (/MDd)

link option:
  추가 디렉토리: D:\SDK\boost_1_35_0
  추가 라이브러리: D:\SDK\boost_1_35_0\bin.v2\libs\regex\build\msvc-8.0\debug\link-static\threading-multi\libboost_regex-vc80-mt-gd-1_35.lib

    2) 수동으로 만들어 놓은 library의 경우.
 compile option:
  추가 include 디렉토리: D:\SDK\boost_1_35_0
  Runtime Library: Multi-threaded Debug DLL (/MDd)
  preprocessor defines: BOOST_REGEX_NO_LIB (또는 BOOST_ALL_NO_LIB)

link option:
  추가 디렉토리: D:\SDK\boost_1_35_0
  추가 라이브러리: D:\SDK\boost_1_35_0\bin.v2\libs\regex\build\msvc-8.0\debug\link-static\threading-multi\libboost_regex-vc80-mt-gd-1_35.lib
  여기서  BOOST_REGEX_NO_LIB은 regex 모듈을 자동으로 링크하지 않겠다는 뜻이다.
  BOOST_ALL_NO_LIB은 모두 자동으로 링크하지 않겠다는 뜻.


6. 테스트.

아래 예제는 MSDN에 있는 regex 예제이다. std::tr1을 boost 예제에 맞게 고쳤다.
#include "stdafx.h"
#include <boost/regex.hpp>
#include <boost/regex/v4/regex.hpp>
#include <boost/regex/config.hpp>
#include <iostream>

int main()
{
    const char *first = "abcd";
    const char *last = first + strlen(first);
    boost::cmatch mr;
    boost::regex rx("abc");
    boost::regex_constants::match_flag_type fl =
        boost::regex_constants::match_default;

    std::cout << "search(f, f+1, \"abc\") == " << std::boolalpha
        << regex_search(first, first + 1, rx, fl) << std::endl;

    std::cout << "search(f, l, \"abc\") == " << std::boolalpha
        << regex_search(first, last, mr, rx) << std::endl;
    std::cout << "  matched: \"" << mr.str() << "\"" << std::endl;

    std::cout << "search(\"a\", \"abc\") == " << std::boolalpha
        << regex_search("a", rx) << std::endl;

    std::cout << "search(\"xabcd\", \"abc\") == " << std::boolalpha
        << regex_search("xabcd", mr, rx) << std::endl;
    std::cout << "  matched: \"" << mr.str() << "\"" << std::endl;

    std::cout << "search(string, \"abc\") == " << std::boolalpha
        << regex_search(std::string("a"), rx) << std::endl;

    std::string str("abcabc");
    boost::match_results<std::string::const_iterator> mr2;
    std::cout << "search(string, \"abc\") == " << std::boolalpha
        << regex_search(str, mr2, rx) << std::endl;
    std::cout << "  matched: \"" << mr2.str() << "\"" << std::endl;

    return (0);
}


실행화일이 만들어 졌다면, 잘 된 것이다.


* note:
  boost jam (bjam) 으로 빌드하면 무엇인가 딱 딱 맞아 떨어지는 것 같아서 좋기도 하지만,
  사용자가 빈번하게 프로젝트를 만들려고 한다면, 매번 lib 모듈을 다 지정해야 하기 때문에 매우 귀찮아 진다. 이를 해결하기 위해서는 '4'번 항목처럼 수동으로 통짜로 lib를 만들고 '5'번에서 처럼 BOOST_ALL_NO_LIB 을 사용하면 매우 편하게 진행 할 수 있다.

TAGS.

Comments