title: Undefined symbols for architecture x86_64, shared Util Library, build with cmake,
body: <p>I have a simple yet perplexing problem.  I have searched around stack overflow and the web and I haven't found anything that helps. I am aware that this problem is common and similar questions have been asked on stack overflow, but they haven't helped me solve this issue;</p>
  
  <p>I am building an application that uses ITK and VTK in C++.  It is built using cmake with unix make,  I am using OS X 10.8.4 and compiling using g++-4.2.  I have a structure that looks like this:</p>
  
  <pre><code>    src
  ├── VascSeg //contains ITK filters that I have written
  ├── lib //contains header/source for some utility functions that I commonly use
  └── test //contains tests for VascSeg Library
  </code></pre>
  
  <p>Here is the error I am getting:</p>
  
  <pre><code>Undefined symbols for architecture x86_64:
    "void MyUt::print_vector&lt;float&gt;(std::vector&lt;float, std::allocator&lt;float&gt; &gt;&amp;, char const*)", referenced from:
        _main in VascularLevelSetTest.cxx.o
  
    "void MyUt::DeepCopy&lt;itk::Image&lt;float, 2u&gt; &gt;(itk::Image&lt;float, 2u&gt; const*, itk::Image&lt;float, 2u&gt;::Pointer)", referenced from:          itk::CommandLevelSetObserver&lt;...&gt;in VascularLevelSetTest.cxx.o
        itk::CommandLevelSetObserver&lt;...&gt;:
  :SaveWriteImage(...)in VascularLevelSetTest.cxx.o
  ld: symbol(s) not found for architecture x86_64
  </code></pre>
  
  <p>Generally, this is an error with an improper include or improper link.  However, there are a number of other functions that I am using in these files and they work fine...  I also recently change the structure of the files to use a header(.h) with source (.cxx) structure.  Previously, I put the declaration and the implementation in a single .h file.  The file got too long and disorganized so I refactored to header/source structure.</p>
  
  <p>Relevant Lines:</p>
  
  <pre><code>using namespace MyUt;
  ...
  std::vector&lt;std::vector&lt;float&gt; &gt; paramList_p1
  std::vector&lt;float&gt; params1 = paramList_p1[config];
  ...
  
  print_vector &lt;float&gt; (params1,"\t");
  </code></pre>
  
  <p>MyUtils.h:</p>
  
  <pre><code>namespace MyUt{
  ...
  template&lt;class T&gt;
  void print_vector(std::vector&lt;T&gt; &amp;vec,const char* end = "\t");
  ...
  }
  </code></pre>
  
  <p>MyUtils.cxx:</p>
  
  <pre><code>namespace MyUt{
  ...
  template&lt;class T&gt;
  void print_vector(std::vector&lt;T&gt; &amp;vec,const char* end = "\t")
  {...}
  ...
  }
  </code></pre>
  
  <p>lib/CMakeLists.txt:</p>
  
  <pre><code>add_library(MyUtils SHARED MyUtils.cxx 
              vtkUtils.cxx)
  SET_TARGET_PROPERTIES(MyUtils PROPERTIES LINKER_LANGUAGE CXX)
  target_link_libraries(MyUtils ${ITK_LIBRARIES} ${VTK_LIBRARIES})
  </code></pre>
  
  <p>test/CMakeLists.txt:</p>
  
  <pre><code>add_executable(VST VascularLevelSetTest.cxx)
  TARGET_LINK_LIBRARIES(VST MyUtils)
  TARGET_LINK_LIBRARIES(VST ${ITK_LIBRARIES})
  </code></pre>
  
  <p>I am sorry if this is a repeat question but all the ones I found didn't help me.</p>
  
  <p>EDIT:</p>
  
  <p>I left out the lines for the DeepCopy error, but I figured that the problems are likely related. So I left it out to keep my post more concise.</p>