title: C++ testing classes with Catch
body: <p>I decided to make a small project which I will cover with tests as much as I can. I'm using CLion (which uses CMake) and Catch library for testing.</p>
  
  <p>The problem is that I'm getting <code>undefined reference to TestClass::add</code> method while I run test class.</p>
  
  <p>Here is my setup (it's a dummy one since I wanted to make sure if everything works):</p>
  
  <p><strong>TestClass.h</strong></p>
  
  <pre><code>#ifndef LLL_TESTCLASS_H
  #define LLL_TESTCLASS_H
  
  class TestClass {
  public:
      int add(int a, int b);
  };
  
  #endif //LLL_TESTCLASS_H
  </code></pre>
  
  <p><strong>TestClass.cpp</strong></p>
  
  <pre><code>#include "TestClass.h"
  int TestClass::add(int a, int b) {
      return a + b;
  }
  </code></pre>
  
  <p><strong>test.cpp -- file with tests</strong></p>
  
  <pre><code>#define CATCH_CONFIG_MAIN
  #include "catch.hpp"
  #include "../src/TestClass.h"
  
  TEST_CASE("addition") {
      TestClass testClass;
      REQUIRE(testClass.add(2,3) == 5);
      REQUIRE(testClass.add(-1, 1) == 0);
      REQUIRE(testClass.add(2, 4) == 1);
  }
  </code></pre>
  
  <p><strong>CMakeLIsts.txt</strong></p>
  
  <pre><code>cmake_minimum_required(VERSION 3.2)
  project(LLL)
  
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  
  set(LIB_DIR "lib")
  include_directories(${LIB_DIR}/Catch)
  include_directories(${LIB_DIR}/Eigen)
  
  set(SRC_DIR src)
  set(SOURCE_FILES ${SRC_DIR}/main.cpp src/TestClass.h src/TestClass.cpp)
  add_executable(LLL ${SOURCE_FILES})
  
  set(TEST_DIR test)
  set(TEST_FILES ${TEST_DIR}/test.cpp)
  add_executable(LLL_TEST ${TEST_FILES})
  </code></pre>