You are viewing...

Dabbling in C++, Using Boost

Updated on September 07, 2016 at the 04th hour
Posted under:

DISCLAIMER: All views are considered my own and you should not draw any conclusions on associates.

To start off, I'm using a Mac and you know we have homebrew to install things, so lets use it to use boost in our C++ program.

To install homebrew:
Go to http://brew.sh/ and you follow the instructions to get it

Install boost:
`brew install boost`

Verify boost is installed:
`brew list | grep 'boost'`

Great, once it is verified now we need to include BOOST into our CMake project.

Open up CMakeLists.txt and make sure you have the below (USE C++ 14 PLS):

cmake_minimum_required(VERSION 3.6)

project("PROJECT_NAME_HERE")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")

FIND_PACKAGE(Boost COMPONENTS thread system)

INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})

add_executable(TARGET_NAME_HERE main.cc)

target_link_libraries(TARGET_NAME_HERE ${Boost_LIBRARIES})


Personally, I think FIND_PACKAGE is nice since you do not need to pick a specific directory where boost is installed. It will just search and expose some variables such as Boost_LIBRARIES and Boost_INCLUDE_DIRS that you can use elsewhere. Also, you'll likely want to modify the component included as part of the find.

Alright, now regenerate CMake build with the new settings and boom BOOST is now included.

Try to do this:
http://www.boost.org/doc/libs/1_61_0/more/getting_started/unix-variants.html#link-your-program-to-a-boost-library

to verify that boost is successfully linked and your program can run.

I like to think small steps in learning things take you a long way.
You just read "Dabbling in C++, Using Boost". Please share if you liked it!
You can read more recent posts here.