Code snippets‎ > ‎C++‎ > ‎

Boost

Boost provides free peer-reviewed portable C++ source libraries that work well with the C++ Standard Library. Boost libraries are intended to be widely useful, and usable across a broad spectrum of applications. The Boost license encourages both commercial and non-commercial use.

The sub-pages demonstrate functionality of different libraries through small sample programs.

Installation

Windows

Download the boost sources + bjam.exe

Start a visual studio console and execute from the boost root direcotory:

bootstrap.bat

b2.exe --prefix=<path>
address-model=64 toolset=msvc variant=release link=static threading=multi runtime-link=shared cxxflags=/D_ITERATOR_DEBUG_LEVEL=0 install

b2 -a -j5 --prefix=d:\libraries\boost_1_56_0_x86_install address-model=32 toolset=msvc link=static threading=multi runtime-link=shared cxxflags=/D_ITERATOR_DEBUG_LEVEL=0 install
b2 -a -j5 --prefix=d:\libraries\boost_1_56_0_x64_install address-model=64 toolset=msvc link=static threading=multi runtime-link=shared cxxflags=/D_ITERATOR_DEBUG_LEVEL=0 install

Using CMake you can then configure the libraries with:
# Boost
# Set $ENV{BOOST_ROOT} to the right directory.
if (WIN32)
  set(Boost_USE_STATIC_LIBS   ON)
  set(Boost_USE_MULTITHREADED ON)
  set(Boost_USE_STATIC_RUNTIME OFF)

elseif(APPLE)
  set(Boost_USE_STATIC_LIBS   OFF)
  set(Boost_USE_MULTITHREADED ON)
else()
  set(Boost_USE_STATIC_LIBS   OFF)
  set(Boost_USE_MULTITHREADED OFF)
  set(Boost_USE_STATIC_RUNTIME OFF)
endif()
#set(Boost_DEBUG ON)
find_package(Boost COMPONENTS date_time system regex REQUIRED)

IF (WIN32)
  # ============ BUILD SETTINGS FOR WINDOWS ============
  # /Od -> disable optimization
  # /W3 -> warning level
  # /ZI -> program database for edit & continue
  # /Gm -> enable minimal rebuild
  # /RTC1 -> runtime checks: stack frames + uninitialized variables
  # /MDd -> Multi-threaded Dynamic Debug
  # /MP -> Parallel build
  
  set(CMAKE_CXX_FLAGS
    "/MP /EHsc /D_CRT_SECURE_NO_DEPRECATE -DWIN32"
    )
  set(CMAKE_CXX_FLAGS_DEBUG 
    "/MDd /RTC1 /Zi /W3 /Od /DDEBUG"
    )
  set(CMAKE_CXX_FLAGS_RELEASE 
    "/MD /O2"
    )
 
  # Add MFC
  add_definitions(-D_AFXDLL)
  # Use of CMAKE_MFC_FLAG
  # Values:
  # 0: Use Standard Windows Libraries
  # 1: Use MFC in a Static Library
  # 2: Use MFC in a Shared DLL
  set(CMAKE_MFC_FLAG 2)
 
  add_definitions(-D_WIN32_WINNT=0x0501)
  
endif (WIN32)
Note that /MD(d) is for shared runtime libraries and /MT(d) for static runtime libraries.