-
[C++] Boost 라이브러리 설치 & Visual Studio 설정C++/미분류 2022. 3. 10. 16:02
Boost는 C++의 오픈소스 라이브러리 집합입니다.
STL과의 호환성이 높은 라이브러리로, 여러 강력한 템플릿 클래스들을 제공합니다.
Boost Software License라는 독자적인 라이센스를 가지고 있고, 이 라이센스는 상업적 이용을 포함한 대부분의 목적을 허용하고 있습니다.
이번 글에서는 Windows 기반의 Boost 라이브러리를 Visual Studio에서 사용하기 위한 설정에 대해 다룹니다.
1. Boost 다운로드
더보기Boost.org에서 Boost라이브러리를 다운받을 수 있습니다.
현재 Boost의 버전은 1.78.0 입니다.
플랫폼에 맞는 압축 파일을 다운로드 후, 풀어주도록 하겠습니다.
압축을 풀어서 나오는 boost_1_78_0 폴더를 적절한 위치에 배치합니다.
저는 변경이 적은 Program File 내부에 배치했습니다.
2. Bootstrap
더보기boost_1_78_0 폴더 내부의 bootstrap.bat파일을 관리자 권한으로 실행합니다.
위 이미지는 bootstrap.bat파일이 실행된 이후의 이미지 입니다.
실행 이전에는 b2.exe를 포함한 일부 파일이 존재하지 않습니다.
3. 빌드
더보기boost_1_78_0폴더 내부의 b2.exe 파일을 관리자 권한으로 실행합니다.
실행이 완료되면 창이 사라지거나, 위 이미지와 같이 Compiler include path와 Linker library path가 출력됩니다.
위 이미지는 Shell에서 실행시킨 결과입니다.
이것으로 Boost 라이브러리를 사용하기 위한 준비가 끝났습니다.
4. Visual Studio 설정
더보기Visual Studio에서 Boost를 사용하려면, 우선적으로 해 주어야 할 설정이 몇 가지 있습니다.
우선 메뉴 바의 프로젝트 속성에 들어갑니다.
추가 포함 디렉터리에 Boost 라이브러리의 Compiler include path를 입력합니다.
추가 라이브러리 디렉터리에 Boost 라이브러리의 Linker library path를 입력합니다.
이것으로, Visual Studio에서 Boost 라이브러리를 사용할 준비가 끝났습니다.
5. 간단한 예제
더보기Boost 라이브러리는 다양한 기능을 제공합니다.
어떤 기능을 제공하는지는 다른 글에서 다루도록 하고, 이번에는 간단한 난수 생성 예제를 살펴보겠습니다.
#include <iostream> #include <boost/random.hpp> int main() { boost::random::mt19937 rng; boost::random::uniform_int_distribution<> six(1, 6); int x = six(rng); std::cout << x; return 0; }
3
Mersenne Twister 방식을 이용한 난수 생성 알고리즘 입니다.
이 기능은 C++ 11에서 표준으로 채택되었지만, Boost에 있는 기능을 사용해봤습니다.
Boost에서 제공하는 기능들은 Library Documentation 에 정리되어 있습니다.
이후 조금씩 관련 기능들을 살펴보도록 하겠습니다.
감사합니다.
'C++ > 미분류' 카테고리의 다른 글
[C++] 랜덤 이벤트 (확률) 구현하기 (0) 2022.10.06 [Visual Studio] Code style 변경하기 (BSD, K&R) (0) 2022.09.14 [WinAPI] Edit Control에서 Enter키 입력 받기 (0) 2022.06.22 [Visual Studio] LNK2019, LNK1120 (0) 2022.06.13 [Visual Studio] Solution & Project (0) 2022.06.07