Adding Boost To Your C++ Include Path
I just installed Boost via MacPorts; but I didn’t want to have to manually add the include path on the commandline every time I compiled something, especially since I’ll do a lot of small hand-compiles while learning how to use Boost.
So I went looking for a way to instruct g++ to always include the Boost headers in the include search path. The solution was to add the following to my .bash_profile:
# Add MacPorts directories, if they exist.
if [ -d /opt/local ]; then
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
export MANPATH=/opt/local/share/man:$MANPATH
export CPLUS_INCLUDE_PATH=/opt/local/include
fi
It’s the “export CPLUS_INCLUDE_PATH…” line that does the trick. However, while the other two exports append the MacPorts additions before the rest of the system, the last replaces the pre-existing path. So be wary, if you were using it previously you’ll need to modify that line to add whatever else you had too.
Headers found through this environment variable are treated as if they were found through an “-I” flag on the commandline, but any true “-I” flags.
Tagged C++, g++, gcc, Programming