title: C++: get Boost working; questions on include path and linking library
body: <p>I was trying to use Boost.Tokenizer library. In my <code>PROG.cpp</code>, I have the following:</p>
  
  <pre><code>#include &lt;boost/tokenizer.hpp&gt;
  </code></pre>
  
  <p>And my <code>Makefile</code> was initially something like</p>
  
  <pre><code>CXX = g++-4.8
  CXXFLAGS = ## some irrelevant flags
  LDFLAGS = ## some irrelevant flags
  SOURCES = PROG.cpp
  OBJECTS = $(SOURCES:.cpp=.o)
  TARGETS = PROG
  
  $(TARGETS) : $(OBJECTS)
          $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
  
  ## other targets
  </code></pre>
  
  <p>It won't compile, since <code>boost/tokenizer.hpp</code> cannot be found:</p>
  
  <pre><code>fatal error: boost/tokenizer.hpp: No such file or directory
  </code></pre>
  
  <p>Then I manually added the boost include path to <code>CXXFLAGS</code>:</p>
  
  <pre><code>-I/opt/local/include/
  </code></pre>
  
  <p>(which is the path from MacPorts.)</p>
  
  <p>Then I tried to include the Tokenizer library, but in <code>/opt/local/lib/</code> I have <code>libboost_atomic-mt.dylib</code>, <code>libboost_chrono-mt.dylib</code>, etc., but nothing like <code>tokenizer</code>. I was rather confused at the time. I supposed that still wouldn't work since the library was not linked against. Surprisingly, the program built, linked, and ran perfectly.</p>
  
  <p>So I'm really confused now. Here are some questions:</p>
  
  <p>(1) I did not link against boost explicitly, so boost is treated like standard library by the linker?</p>
  
  <p>(2) If boost is treated like standard, why the headers are not standard?</p>
  
  <p>(3) Why there are <code>libboost_atomic-mt.dylib</code>, <code>libboost_chrono-mt.dylib</code>, etc. but not <code>tokenizer</code>? Which dynamic library does <code>tokenizer</code> belong to?</p>
  
  <p>I'm not very familiar with <code>g++</code> linking mechanism; speaking of boost, this is my very first program with boost. <strong>So I'd really appreciate detailed explanation.</strong> Thanks in advance!</p>
  
  <p>For reference, this is what I extracted by <code>gcc -print-search-dirs</code>:</p>
  
  <pre><code>install: /usr/gcc-4.8.0/lib/gcc/x86_64-apple-darwin12.3.0/4.8.0/
  programs: =/usr/gcc-4.8.0/libexec/gcc/x86_64-apple-darwin12.3.0/4.8.0/:/usr/gcc-4.8.0/libexec/gcc/x86_64-apple-darwin12.3.0/4.8.0/:/usr/gcc-4.8.0/libexec/gcc/x86_64-apple-darwin12.3.0/:/usr/gcc-4.8.0/lib/gcc/x86_64-apple-darwin12.3.0/4.8.0/:/usr/gcc-4.8.0/lib/gcc/x86_64-apple-darwin12.3.0/:/usr/gcc-4.8.0/lib/gcc/x86_64-apple-darwin12.3.0/4.8.0/../../../../x86_64-apple-darwin12.3.0/bin/x86_64-apple-darwin12.3.0/4.8.0/:/usr/gcc-4.8.0/lib/gcc/x86_64-apple-darwin12.3.0/4.8.0/../../../../x86_64-apple-darwin12.3.0/bin/
  libraries: =/usr/gcc-4.8.0/lib/gcc/x86_64-apple-darwin12.3.0/4.8.0/:/usr/gcc-4.8.0/lib/gcc/x86_64-apple-darwin12.3.0/4.8.0/../../../../x86_64-apple-darwin12.3.0/lib/x86_64-apple-darwin12.3.0/4.8.0/:/usr/gcc-4.8.0/lib/gcc/x86_64-apple-darwin12.3.0/4.8.0/../../../../x86_64-apple-darwin12.3.0/lib/:/usr/gcc-4.8.0/lib/gcc/x86_64-apple-darwin12.3.0/4.8.0/../../../x86_64-apple-darwin12.3.0/4.8.0/:/usr/gcc-4.8.0/lib/gcc/x86_64-apple-darwin12.3.0/4.8.0/../../../:/lib/x86_64-apple-darwin12.3.0/4.8.0/:/lib/:/usr/lib/x86_64-apple-darwin12.3.0/4.8.0/:/usr/lib/
  </code></pre>