Windows/MFC

How to install and use Boost

aucd29 2013. 10. 2. 18:04

정규표현식을 C++에서 처리하고자 하는 방법을 찾던중 Boost 라이브러리를 알게된 필자는

이를 설치하고 사용하려고 무진장 애를 썼으나 어려웠다;

물론 영어로 된 메뉴얼 읽으면 된다; 하지만 귀찮다 -_-

 

그래서 여기저기서 찾아보고 물어보고 해서 얻은 답을 공유하고자 한다.

 

테스트 환경

OS : Windows XP

VC : Visual Studio .NET 2002

 

1. boost.org 에서 다운 받는다. Download 메뉴를 눌러보면 소스포지로 이동한다.

http://sourceforge.net/project/showfiles.php?group_id=7586

 

2. 일단 임의의 디렉토리에 푼다.

 

3. 압축을 푼 디렉토리에서 ./tools/build/jam_src/ 로 이동한다.

 

4. build.bat -msvc 를 입력하여 bjam 파일을 컴파일한다.

 

5. 컴파일이 끈나면 bin.ntx86 디렉토리가 생기고 거기에 bjam.exe 파일이 있다.

 

6. bjam 파일을 압축을 푼 디렉토리로 이동한다.


 
7. bjam "-sTOOLS=msvc" install 을 cmd 창에서 입력한다.
이때 cmd 창은 Visual Studio .NET 명령 프롬프트를 사용해야 한다.
그렇지 않으면 path 문제로 오류가 나올수 있다.
(추가 2004/05/20 : Visual Studio .NET 2003 에서는 위와 같이 하면 연결시에 버전에 맞는 lib를 못 찾게 된다. 이럴 경우에는 bjam -sTOOLS=vc7.1 install 로 빌드 해 주면 된다.)
 
8. 빌드가 완료되면 다음과 같이 디렉토리가 생성된다.

 
9. 이를 VS 에서 사용하고자 한다면 다음과 같이 셋팅해야 한다.
VS에서 도구 -> 옵션을 이용하여 옵션 대화상자를 연다.
그리고 다음과 같이 셋팅한다.
 


 
10. 모든 설정은 끝났다.
아래는 boost 에 포함된 regex의 예제 파일이다.
----------------------------
#include
#include
#include
using namespace std;
bool validate_card_format(const std::string& s)
{
   static const boost::regex e("(\\d{4}[- ]){3}\\d{4}");
   return boost::regex_match(s, e);
}
const boost::regex e("\\A(\\d{3,4})[- ]?(\\d{4})[- ]?(\\d{4})[- ]?(\\d{4})\\z");
const std::string machine_format("\\1\\2\\3\\4");
const std::string human_format("\\1-\\2-\\3-\\4");
std::string machine_readable_card_number(const std::string& s)
{
   return boost::regex_replace(s, e, machine_format, boost::match_default | boost::format_sed);
}
std::string human_readable_card_number(const std::string& s)
{
   return boost::regex_replace(s, e, human_format, boost::match_default | boost::format_sed);
}
 
int main()
{
   string s[4] = { "0000111122223333", "0000 1111 2222 3333",
                   "0000-1111-2222-3333", "000-1111-2222-3333", };
   int i;
   for(i = 0; i < 4; ++i)
   {
      cout << "validate_card_format(\"" << s[i] << "\") returned " << validate_card_format(s[i]) << endl;
   }
   for(i = 0; i < 4; ++i)
   {
      cout << "machine_readable_card_number(\"" << s[i] << "\") returned " << machine_readable_card_number(s[i]) << endl;
   }
   for(i = 0; i < 4; ++i)
   {
      cout << "human_readable_card_number(\"" << s[i] << "\") returned " << human_readable_card_number(s[i]) << endl;
   }
   return 0;
}
 

----------------------------------------
실행시켜보면 boost가 제대로 작동한다는걸 확인할 수 있다.
 
 
내가 다시 boost를 깔게 될때 삽질할지도 모르고,
boost 깐다고 고생하는 분들이 있을수도 있기에 한번 작성해 본다...
 

글쓴이 : 경북대학교 컴퓨터과학과 송진태

그냥 긁어가시면 섭해요~ 자취 남겨 주세요~ ㅡ_ㅜ