#DevStudy/C++ Boost
MacOS에서 boost 라이브러리 환경 구성하기
검은_백조
2022. 8. 5. 14:25
Boost Install
brew install boost
CMake Install
brew install cmake
Example
cpp_boost라는 프로젝트 폴더를 만들어주고 아래 두 파일을 생성한다.
CMakeLists.txt
CMake를 이용해서 자동으로 프로젝트가 세팅되도록 할 것이다.
cmake_minimum_required(VERSION 3.16)
project(cpp_boost)
set(CMAKE_CXX_STANDARD 14)
#Boost 라이브러리 설치 확인
find_package(Boost)
if(Boost_FOUND)
# include 패스 설정
include_directories(${Boost_INCLUDE_DIRS})
endif()
add_executable(cpp_boost 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;
}
프로젝트 세팅
두 파일이 위치한 폴더로 이동한 후 아래 명령어를 실행한다.
>> cmake .
-- The C compiler identification is AppleClang 13.1.6.13160021
-- The CXX compiler identification is AppleClang 13.1.6.13160021
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Boost: /usr/local/lib/cmake/Boost-1.79.0/BoostConfig.cmake (found version "1.79.0")
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/yhjang/cpp_boost
실행에 성공하면 이러한 폴더 구성이 될 것이다.
컴파일
컴파일을 하면 cpp_boost라는 파일이 생성될 것이다.
>> make
[ 50%] Building CXX object CMakeFiles/cpp_boost.dir/main.cpp.o
[100%] Linking CXX executable cpp_boost
[100%] Built target cpp_boost
실행해주자.
>> ./cpp_boost
Boost version: 1.79.0
레퍼런스
https://object-world.tistory.com/9
macOS에서 부스트(Boost)라이브러리 사용하기
Home brew(홈 브루) macOS용 패키지 관리자로 터미널에서 명령을 통해 쉽게 필요한 프로그램을 설치, 삭제, 업데이트 할 수 있다. 이는 RedHat 계열의 리눅스에서 사용하는 yum 이나 Ubuntu 계열의 리눅스
object-world.tistory.com
https://popcorn16.tistory.com/57
CMake로 Boost 라이브러리 링킹하기
main.cpp와 CMakeLists.txt를 만들고 아래 코드를 복붙합니다. // main.cpp #include #include using namespace std; namespace fs = boost::filesystem; int main() { string str = "/Users/kwon/Documents/blog/..
popcorn16.tistory.com