1

I'm running Mac OSX 10.9.2 (Mavericks) and I use Xcode 5.1.

I've been doing tons of researching into how to properly include Boost files in my program, but I simply can't do it. I currently have boost saved at /usr/local/include/boost/. Whenever I tried to include boost files, it either doesn't compile, or it can't find the file, or if it does find the file, it collides with some other file that already exists (that's what it seems like to me). Can someone please provide a detailed explanation of how to do this properly and preferably provide a code snippet of some sort? Please include several different boost files (i.e., ones that exist at the top level of the boost directory, but also those that exist within subdirectories, like algorithm files).

Simon Ayzman
  • 247
  • 3
  • 5
  • 12

1 Answers1

0

There are essentially two types of inclusions when using boost library:

  1. Libraries
  2. Include only templates

For example, array is a template only include, so when compiling you need to send this flag to your clang: -I/usr/local/include/

this way when including the array you would do it like this:

#include "boost/array.hpp"

When including a library you must build boost on your system, using the b2 batch files. Then you build using the bjam system.

When the libs are build you have to link them to your clang, the flags are a bit different than mere include files, for example lets suppose you want to include the boost regex library which on your system will be named libboost_regex.so, thus you need to tell your compiler the following two flags:

-L/usr/local/{boost_build_place}/lib -lboost_regex

The -L tells your compiler about a folder of libraries you are including to your project and the -l flag tells about the specific library you want, as you can see, when using the -l flag you must remove the lib preamble and the .so.

Claudiordgz
  • 3,023
  • 1
  • 21
  • 48
  • What if I'm using XCode? How do I set those flags accordingly? – Simon Ayzman Mar 20 '14 at 19:37
  • For Xcode include flags [check this thread](http://stackoverflow.com/questions/14134064/how-to-set-include-path-in-xcode-project) and you could also set the library flags in the same place. **In your target's build setting search for "Other C++ Flags" and add -I/usr/local/include/** – Claudiordgz Mar 20 '14 at 19:39