Getting Started with Boost on Mac OSX

Getting Started with Boost on Mac OSX

Install Boost via Homebrew

  1. Install Homebrew if you haven’t: /usr/bin/ruby -e "$(curl -fsSL"

  2. Install boost: brew install boost

Get the Boost Location

First run the command:

brew info boost

Brew Info

Then grab the location. Looking above, you can see my location is /usr/local/Cellar/boost/1.66.0

Create a Boost Program

In a new directory, create a file called main.cpp.

Here is the code example I am using:

#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>

int main()
    using namespace boost::lambda;
    typedef std::istream_iterator<int> in;

        in(std::cin), in(), std::cout << (_1 * 3) << " " );


Then run the following command to compile:

c++ -I /usr/local/Cellar/boost/1.66.0 main.cpp -o boost

Bonus – Create a makefile

If you want to compile with just the make command, create a file called makefile. Then use the following:

flags = -I /usr/local/Cellar/boost/1.66.0

    c++ ${flags} main.cpp -o boost