title: Cannot link boost libraries with CMake
body: <p>I have a sample C++ code that uses boost (program options module) as shown below:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  #include &lt;boost/program_options/options_description.hpp&gt;
  #include &lt;boost/program_options/parsers.hpp&gt;
  #include &lt;boost/program_options/variables_map.hpp&gt;
  
  namespace po = boost::program_options;
  
  int main(int argc, const char* argv[]){
      po::options_description description("MyTool Usage");
  
      description.add_options()
          ("help,h", "Display this help message")
          ("version,v", "Display the version number");
  
      po::positional_options_description p;
  
      po::variables_map vm;
      po::store(po::command_line_parser(argc, argv).options(description).positional(p).run(), vm);
      po::notify(vm);
  
      if(vm.count("help")){
          std::cout &lt;&lt; description;
  
          return 0;
      }
  
      if(vm.count("version")){
          std::cout &lt;&lt; "MyTool Version 1.0" &lt;&lt; std::endl;
  
          return 0;
      }
  
      return 0;
  }
  </code></pre>
  
  <p>I tried to compile using cmake. The corresponding CMakeLists.txt file is shown below:</p>
  
  <pre><code>cmake_minimum_required(VERSION 2.6)
  
  set(CMAKE_CXX_LINK_FLAGS "-std=c++11 -g -Wall -fsigned-char -lboost_program_options-mt")
  
  set(BOOST_ROOT /opt/local/include/boost)
  set(BOOST_LIBRARYDIR /opt/local/lib)
  find_package(Boost COMPONENTS program_options system filesystem REQUIRED)
  include_directories(${BOOST_INCLUDE_DIR})
  link_libraries(${BOOST_LIBRARIES})
  
  add_executable(testboostpo testboostpo_simple.cpp)
  target_link_libraries(testboostpo ${Boost_LIBRARIES})
  </code></pre>
  
  <p>Although <code>cmake .</code> seems to succeed and it also detects all the boost modules I typically use (program options, system, filesystem), </p>
  
  <pre><code>$ cmake .
  -- The C compiler identification is GNU 5.5.0
  -- The CXX compiler identification is GNU 5.5.0
  -- Checking whether C compiler has -isysroot
  -- Checking whether C compiler has -isysroot - yes
  -- Checking whether C compiler supports OSX deployment target flag
  -- Checking whether C compiler supports OSX deployment target flag - yes
  -- Check for working C compiler: /opt/local/bin/gcc-mp-5
  -- Check for working C compiler: /opt/local/bin/gcc-mp-5 -- works
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- Checking whether CXX compiler has -isysroot
  -- Checking whether CXX compiler has -isysroot - yes
  -- Checking whether CXX compiler supports OSX deployment target flag
  -- Checking whether CXX compiler supports OSX deployment target flag - yes
  -- Check for working CXX compiler: /opt/local/bin/g++-mp-5
  -- Check for working CXX compiler: /opt/local/bin/g++-mp-5 -- works
  -- Detecting CXX compiler ABI info
  -- Detecting CXX compiler ABI info - done
  -- Detecting CXX compile features
  -- Detecting CXX compile features - done
  -- Boost version: 1.66.0
  -- Found the following Boost libraries:
  --   program_options
  --   system
  --   filesystem
  -- Configuring done
  -- Generating done
  -- Build files have been written to: /Users/params/libraries/coding_interview/every_test/boost_test
  </code></pre>
  
  <p>the next step <code>make</code> fails with the following error:
  $ make</p>
  
  <pre><code>Scanning dependencies of target testboostpo
  [ 50%] Building CXX object CMakeFiles/testboostpo.dir/testboostpo_simple.cpp.o
  [100%] Linking CXX executable testboostpo
  ld: library not found for -lboost_program_options-mt
  collect2: error: ld returned 1 exit status
  make[2]: *** [testboostpo] Error 1
  make[1]: *** [CMakeFiles/testboostpo.dir/all] Error 2
  make: *** [all] Error 2
  </code></pre>
  
  <p>There seems to be a problem linking boost library for program options. However, I can see that the library is installed at <code>/opt/local/lib/libboost_program_options-mt.dylib</code></p>
  
  <p>Alternatively, I also tried isolating the compilation but it fails as well.</p>
  
  <pre><code>$ g++ -L/opt/local/lib testboostpo_simple.cpp -lboost_program_options-mt
  Undefined symbols for architecture x86_64:
    "boost::program_options::to_internal(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)", referenced from:
        std::vector&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, std::allocator&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; boost::program_options::to_internal&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;(std::vector&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, std::allocator&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; const&amp;) in ccg8tggM.o
    ld: symbol(s) not found for architecture x86_64
  collect2: error: ld returned 1 exit status
  
  $ g++ -L/opt/local/lib testboostpo_simple.cpp /opt/local/lib/libboost_program_options-mt.dylib
  Undefined symbols for architecture x86_64:
    "boost::program_options::to_internal(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)", referenced from:
        std::vector&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, std::allocator&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; boost::program_options::to_internal&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;(std::vector&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, std::allocator&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; const&amp;) in ccg8tggM.o
    ld: symbol(s) not found for architecture x86_64
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>I am using gcc5, boost 1.66 and cmake 3.12 (all of them installed using macports).
  boost header files are in location:
  <code>/opt/local/include/boost/</code>
  and the boost library files are in location:
  <code>/opt/local/lib</code></p>
  
  <p>Does anybody here know what might be causing the boost linking to still fail despite providing the paths? Anything else missing here or incorrectly specified?</p>
  
  <p>Thanks,</p>