title: CMake: undefined reference to
body: <p>I use CMake 3.5.2. When trying to build my C++ code I get the following error:</p>
  
  <pre><code>[100%] Linking CXX executable SomeExecutable
  CMakeFiles/SomeExecutable.dir/Common/src/FunctionOne.cpp.o: In function `FunctionOne::FunctionOne(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, double, double, unsigned int, bool)':
  FunctionOne.cpp:(.text+0x490): undefined reference to `Helper::initLevel(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, bool)'
  </code></pre>
  
  <p>The program doesn't find Helper::initLevel() in myLib.so. How do I fix it?</p>
  
  <p><strong>CMakeLists.txt: (shortened for brevity)</strong></p>
  
  <pre><code>cmake_minimum_required(VERSION 3.0)
  project(ProjectName)
  
  add_definitions(-std=c++11)
  add_definitions(-Wall)
  add_definitions(-O2)
  
  link_directories(/usr/local/lib)    
  
  add_executable(SomeExecutable SomeExecutable.cpp ${FunctionOne} ${FunctionTwo})
  target_link_libraries(SomeExecutable -pthread -lboost_thread ${Boost_LIBRARIES} myLib armadillo)
  </code></pre>
  
  <p><strong>File structure (shortened for brevity):</strong></p>
  
  <pre><code>├── bin
  ├── CMakeCache.txt
  ├── cmake_install.cmake
  ├── CMakeLists.txt
  ├── Common
  │   ├── include
  │   │   ├── dataContainer.h
  │   │   ├── FunctionOne.h
  │   │   ├── FunctionTwo.h
  │   └── src
  │       ├── FunctionOne.cpp
  │       └── FunctionTwo.cpp
  ├── SomeExecutable.cpp
  ├── myLib
  │   ├── example.cpp
  │   ├── include
  │   │   ├── Config.h
  │   │   ├── Helper.h
  │   ├── libmyLib.so
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p><strong>myLib/include/Config.h:</strong></p>
  
  <pre><code>Namespace Helper {
  [...]
      Level* initLevel(const std::string&amp; jsonLvlPath, bool twiceSpatPts =        false);
  [..]
  }
  </code></pre>
  
  <p><strong>UPDATE 2:</strong></p>
  
  <pre><code>kepj@laptop:~/ProjectName$ make VERBOSE=1
  /usr/bin/cmake -E cmake_link_script CMakeFiles/SomeExecutable.dir/link.txt --verbose=1
  /usr/bin/c++      CMakeFiles/SomeExecutable.dir/SomeExecutable.cpp.o CMakeFiles/SomeExecutable.dir/Common/src/FunctionOne.cpp.o CMakeFiles/SomeExecutable.dir/Common/src/FunctionTwo.cpp.o SomeExecutable  -L/usr/local/lib -rdynamic -pthread -lboost_thread -lboost_system -lboost_filesystem -lmyLib -lsymbolicc++ -lmatio -larmadillo -Wl,-rpath,/usr/local/lib 
  CMakeFiles/SomeExecutable.dir/Common/src/FunctionTwo.cpp.o: In function `FunctionTwo::FunctionTwo(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, double, double, unsigned int, bool)':
  FunctionTwo.cpp:(.text+0x490): undefined reference to `Helper::initLevel(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, bool)'
  collect2: error: ld returned 1 exit status
  CMakeFiles/SomeExecutable.dir/build.make:174: recipe for target 'SomeExecutable' failed
  make[2]: *** [SomeExecutable] Error 1
  make[2]: Leaving directory '/home/kepj/ProjectName'
  CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/SomeExecutable.dir/all' failed
  make[1]: *** [CMakeFiles/SomeExecutable.dir/all] Error 2
  make[1]: Leaving directory '/home/kepj/ProjectName'
  Makefile:83: recipe for target 'all' failed
  make: *** [all] Error 2
  </code></pre>