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 https://raw.githubusercontent.com/Homebrew/install/master/install)"

  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;

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

Compile

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

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s