Installation boost library in Ubuntu
Download source
Installation
apt-get install libboost-all-dev
The installed libraries are located in /usr/include/boost
Example
기본적으로 include 파일은
#include <boost/xxxx.hpp> 또는 #include "boost/xxxx.hpp" 로 사용하면 된다.
주의: boost directory 는 기존 c++ 컴파일러가 자동으로 include 하는 디렉토리가 아니기 때문에 -I 옵션에 boost directory 를 명시해 주어야 한다.
/**
* To compile:
* g++ -o test test.cpp -I/usr/include -lboost_thread -lboost_system -lboost_date_time
*/
#include <iostream>
#include <boost/thread.hpp>
#include <boost/date_time.hpp>
void workFunc()
{
boost::posix_time::seconds workTime(3);
std::cout << "Worker: running" << std::endl;
boost::this_thread::sleep(workTime);
std::cout << "Worker: finished" << std::endl;
}
int main(int argc, char** argv)
{
std::cout << "main: startup" << std::endl;
boost::thread workerThread(workFunc);
std::cout << "main: waiting for thread finish" << std::endl;
workerThread.join();
std::cout << "main: done" << std::endl;
return 0;
}
Compile
컴파일 옵션 예제
-I 는 boost header file 이 존재하는 폴더를 명시함
-l은 dynamic library 를 사용할 경우 명시함 (ex. -lboost_system 이라고 하면 libboost_system.so library를 포함하는 것임)
g++ -o hello hello.cpp -I/usr/include -lboost_xxx
Reference
boost homepage: http://www.boost.org/
Unix에서 설치 방법: http://www.boost.org/doc/libs/1_57_0/more/getting_started/unix-variants.html