title: Custom CMake library - What have I done wrong?
body: <p>I am trying to install a custom library with CMake.</p>
  <p>It consists of 2 'sub-libraries' and a main header file which includes the 'sub-libraries'.</p>
  <p>I think it installs okay (The output looks like this:)</p>
  <pre><code>-- Configuring done
  -- Generating done
  -- Build files have been written to: /home/pi/Desktop/Projects/MaxLib/build
  [ 20%] Building CXX object Geom/CMakeFiles/Geom.dir/Geom.cpp.o
  [ 40%] Linking CXX shared library libGeom.so
  [ 40%] Built target Geom
  [ 60%] Building CXX object File/CMakeFiles/File.dir/File.cpp.o
  [ 80%] Linking CXX shared library libFile.so
  [ 80%] Built target File
  [100%] Built target MaxLib
  Install the project...
  -- Install configuration: &quot;Debug&quot;
  -- Installing: /usr/local/lib/libMaxLib.a
  -- Installing: /usr/local/include/MaxLib.h
  -- Installing: /usr/local/include/MaxLib/File.h
  -- Installing: /usr/local/include/MaxLib/Geom.h
  </code></pre>
  <p>However, when I try to compile a program using it, I receive a number of &quot;undefined reference to&quot; errors. Where have I gone wrong?</p>
  <p>The Main Header looks like:</p>
  <pre><code>#include &quot;MaxLib/File.h&quot;
  #include &quot;MaxLib/Geom.h&quot;
  </code></pre>
  <p>It's CMakefile looks like this:</p>
  <pre><code>cmake_minimum_required(VERSION 3.5)
  
  project(MaxLib)
  
  add_library(${PROJECT_NAME}
      &quot;${CMAKE_CURRENT_SOURCE_DIR}/MaxLib.h&quot;
  )
  
  add_subdirectory(File)
  add_subdirectory(Geom)
  target_link_libraries(${PROJECT_NAME} File)
  target_link_libraries(${PROJECT_NAME} Geom)
  
  # Install Library
  install (TARGETS ${PROJECT_NAME}
      LIBRARY DESTINATION lib)
  
  # Install Main Header File
  INSTALL(FILES &quot;${CMAKE_CURRENT_SOURCE_DIR}/MaxLib.h&quot; DESTINATION include) # 
  INSTALL(FILES ...) or install(DIRECTORY ...) 
  
  # Build list of header files to install from other directorys. Root == &quot;.&quot;
  set(HEADER_DIRS &quot;File&quot; &quot;Geom&quot;)
  ## Add Source Files from the other directories
  foreach(DIR ${HEADER_DIRS})
      # Find all source files &amp; append to list
      if(DIR STREQUAL &quot;.&quot;)
          file(GLOB HEADER_FILES_IN_FOLDER *.h)
      else()
          file(GLOB HEADER_FILES_IN_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/${DIR}/*.h)
      endif()
      list(APPEND HEADER_FILES ${HEADER_FILES_IN_FOLDER})
  endforeach()
  # Install Header files
  INSTALL(FILES ${HEADER_FILES} DESTINATION include/${PROJECT_NAME}) # INSTALL(FILES ...) or install(DIRECTORY ...) 
  
  target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic -g) 
  set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)
  </code></pre>
  <p>The 'sub-libraries's CMakefiles look like this:</p>
  <pre><code>project(Geom)
  
  add_library(${PROJECT_NAME} SHARED
      ${CMAKE_CURRENT_SOURCE_DIR}/Geom.cpp
  )
  
  target_include_directories(${PROJECT_NAME}
      PUBLIC 
          ${CMAKE_CURRENT_SOURCE_DIR}
  )
  </code></pre>
  <p>I am trying to include the library like this:</p>
  <pre><code>#include &lt;MaxLib.h&gt;
  </code></pre>
  <p>And I am adding -lMaxLib to its makefile</p>
  <p><strong>Edit:</strong></p>
  <p>A basic program like this:</p>
  <pre><code>#include &lt;MaxLib.h&gt;
  
  int main() {
      float y1 = MaxLib::Geom::CleanAngle(7654);
  }
  </code></pre>
  <p>Will produce the undefined reference error:</p>
  <pre><code>/usr/bin/ld: warning: libFile.so, needed by //usr/local/lib/libMaxLib.so, not found (try using -rpath or -rpath-link) // This shows when add_library marked SHARED
  /usr/bin/ld: warning: libGeom.so, needed by //usr/local/lib/libMaxLib.so, not found (try using -rpath or -rpath-link) // This shows when add_library marked SHARED
  /home/pi/Desktop/Projects/TestProgram/main.cpp:43: undefined reference to `MaxLib::Geom::CleanAngle(double)'
  </code></pre>