C++ with Boost
macOS에서 부스트(Boost)라이브러리 사용하기
basker
2020. 7. 10. 15:47
Home brew(홈 브루)
macOS용 패키지 관리자로 터미널에서 명령을 통해 쉽게 필요한 프로그램을 설치, 삭제, 업데이트 할 수 있다. 이는 RedHat 계열의 리눅스에서 사용하는 yum 이나 Ubuntu 계열의 리눅스에서 사용하는 apt-get과 같다고 생각하면 된다.
Home brew 설치
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Home brew 업데이트
$ brew update
Home brew 삭제
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
Home brew 에 대한 자세한 내용은 해당 링크를 참조하면 된다.
brew를 통해서 설치된 패키지는 /usr/local/Cellar에서 확인할 수 있다.
Boost(부스트) 라이브러리 설치
브루 사이트에서 boost 라이브러리를 찾으면 현재 boost@1.72 버전을 확인할 수 있다.
$ brew install boost
설치가 완료되면 /usr/local/Cellar/boost 에 개발을 위한 헤더 파일과 라이브러리 파일이 설치된다.
C++ 프로젝트 빌드를 위한 CMake 설치
$ brew install cmake
Boost 라이브러리 테스트 코드 작성
CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(boost_test)
set(CMAKE_CXX_STANDARD 14)
#Boost 라이브러리 설치 확인
find_package(Boost)
if(Boost_FOUND)
# include 패스 설정
include_directories(${Boost_INCLUDE_DIRS})
endif()
add_executable(boost_test main.cpp)
main.cpp
#include <boost/version.hpp>
#include <cstdio>
int main() {
printf("Boost version: %d.%d.%d\n",
BOOST_VERSION / 100000,
(BOOST_VERSION / 100) % 1000,
BOOST_VERSION % 100);
return 0;
}
boost_test 폴더 생성 후 두 파일을 해당 폴더에 위치 시키고 cmake를 이용해 빌드한다.
$ mkdir cmake_build_debug
$ cd cmake_build_debug/
$ cmake -DCMAKE_BUILD_TYPE=Debug ..
$ make
빌드가 성공적이면 이제 Boost 라이브러리를 사용할 수 있다.