2013년 9월 3일 화요일

boost 라이브러리 설치방법 ( 우분투 13.04, boost 1.53 )

1. 업데이트를 해준다.
    sudo apt-get update && sudo apt-get upgrade

2. 빌드에 필요한 구성요소를 설치해준다.
    sudo apt-get install build-essential
    sudo apt-get install python-dev
    sudo apt-get install libzip-dev
    sudo apt-get install libbz-dev

3. boost 홈페이지에서 버전에 맞게 받는다.

4. 압축을 풀어준다.
    tar xzvf boost_1_53_0.tar.gz

5. 압축을 푼 디렉토리를 /usr/local/ 에 위치시킨다.
   sudo mv boost_1_53_0/ /usr/local/

6. sudo ./bootstrap.sh를 실행한다.

7. bootstrap을 실행하면 bjam이라는 파일이 나온다.
   sudo ./bjam link=static stage




test.cpp
#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;
    }
}

Makefile
CC=g++
CPPFLAGS=-O2 -I/usr/local/boost_1_53_0
LDFLAGS=-L/usr/local/boost_1_53_0/stage/lib

LDLIBS=-lboost_regex

all: test

clean:
rm -rf test
rm -rf *.o



7. make를 실행하여 컴파일이 잘 되었는지 확인한다.
    make

8. ldd test를 실행하여 이상이 없는지 확인한다.
   ldd test


9. ./test를 실행하면 대기상태로 나오는데 아래와 같이 입력한다.
입력 - Subject: Will Success Spoil Rock Hunter?
출력 - Success Spoil Rock Hunter?


10. makefile을 편하게 사용하기 위해 .bashrc파일을 수정한다.
original Makefile
CC=g++
CPPFLAGS=-O2 -I/usr/local/boost_1_53_0
LDFLAGS=-L/usr/local/boost_1_53_0/stage/lib
LDLIBS=-lboost_regex

all: test

clean:
rm -rf test
rm -rf *.o

.bashrc
# by gilgil

export CPPFLAGS="-I/usr/local/boost_1_53_0"
export LDFLAGS="-L/usr/local/boost_1_53_0/stage/lib"


modified Makefile
CC=g++
CPPFLAGS+=-O2
LDLIBS=-lboost_regex

all: test

clean:
rm -rf test
rm -rf *.o



출처 : . http://gilgil.net/?document_srl=7273
           http://threadbuilder.wordpress.com/2013/03/26/ubuntu-eclipse-boost-setting/
           http://gilgil.net/8563

댓글 1개: