title: undefined reference with shared library using cmake
body: <p>I have looked a lot of placed to find this answer, but I have not been able to find anything that pertains to my situation.  It seems so easy, which is why this is so frustrating.</p>
  
  <p>I am building a project with CMAKE.  I am generating two shared libraries.  One includes the other.  I am also generating an executable.  The executable is linking to the shared library that encapsulates the other one.  Here is the relevant portion of the code:</p>
  
  <pre><code>################################################################################ 
  # Make the shared libraries                                                             
  ################################################################################ 
  # Standard stuff                                                                 
  add_library(er SHARED src/std_math.cc src/snapshot.cc)                           
  include_directories(hdr)                                                         
  target_link_libraries(er rt)                                                     
  
  # DSP library                                                                    
  add_library(dsp SHARED src/dsp.cc)                                               
  include_directories(hdr)                                                         
  target_link_libraries(dsp er /usr/lib/libfftw3f.so /usr/lib/libfftw3.so)         
  
  ################################################################################ 
  # Make an Executable                                                             
  ################################################################################ 
  message("-- Making executable for testing --")                                   
  add_executable(er_test test/dsp_test.cc)                                         
  include_directories(hdr)                                                         
  target_link_libraries(er_test dsp)                                               
  
  ################################################################################ 
  # What to do with make install                                                   
  ################################################################################ 
  message ("-- Writting install scripts --")                                       
  
  # See if there is an install directory already assigned.  If not, set it to the  
  # system default.                                                                
  if (NOT DEFINED INSTALL_DIR)                                                     
      set (INSTALL_DIR /usr/local/)                                                
  endif (NOT DEFINED INSTALL_DIR)                                                  
  message ("  -- install_dir = ${INSTALL_DIR}")                                    
  
  # Install the libraries and header files to the appropriate places               
  install (TARGETS er dsp DESTINATION ${INSTALL_DIR}/bin)                          
  install (FILES hdr/dsp.hh hdr/snapshot.hh hdr/std_math.hh DESTINATION ${INSTALL_DIR}/include)
  </code></pre>
  
  <p>Here is the error I get.  </p>
  
  <pre><code>CMakeFiles/er_test.dir/test/dsp_test.cc.o: In function `main':
  dsp_test.cc:(.text.startup+0x11e): undefined reference to `std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp; operator&lt;&lt; &lt;int&gt;(std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;, std::vector&lt;int, std::allocator&lt;int&gt; &gt; const&amp;)'
  dsp_test.cc:(.text.startup+0x142): undefined reference to `std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp; operator&lt;&lt; &lt;int&gt;(std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;, std::vector&lt;int, std::allocator&lt;int&gt; &gt; const&amp;)'
  dsp_test.cc:(.text.startup+0x166): undefined reference to `std::vector&lt;int, std::allocator&lt;int&gt; &gt; subvec&lt;int&gt;(std::vector&lt;int, std::allocator&lt;int&gt; &gt; const&amp;, int, int, int)'
  dsp_test.cc:(.text.startup+0x182): undefined reference to `std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp; operator&lt;&lt; &lt;int&gt;(std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;, std::vector&lt;int, std::allocator&lt;int&gt; &gt; const&amp;)'
  dsp_test.cc:(.text.startup+0x1b6): undefined reference to `std::vector&lt;int, std::allocator&lt;int&gt; &gt; subvec&lt;int&gt;(std::vector&lt;int, std::allocator&lt;int&gt; &gt; const&amp;, int, int, int)'
  </code></pre>
  
  <p>and there are many more where those came from.  I have tried using static libraries, but then it just delays the problem until the next executable I try to include these libraries into.  I have also tried using g++ instead of c++.  I've tried swapping around library orders.  Also, it is not a template issue since at least one of the references it can't find is not a templated function.  I have searched the libraries for the symbols, and I was able to find them, although they were prepended and postpended by random characters.</p>
  
  <p>I don't understand what's going on.  Please help.</p>
  
  <p>Thanks,</p>
  
  <p>UPDATE</p>
  
  <p>I found another link, specifically <a href="https://stackoverflow.com/questions/6891447/cmake-variable-scope-add-subdirectory">this one</a>, that mentioned potential problems with add_subdirectory.  This is a subproject to another project.  So I sent into the project and built there.  It worked!  It still doesn't work in the parent directory though.  Maybe that can give clues to someone. </p>
  
  <p>Thanks again,</p>