title: Clion Undefined symbols for architecture x86_64
body: <p>My code compiled and ran as expected in CodeLite.
  Then I tried to run the same code in Clion, but it give me this error:</p>
  
  <pre><code>Scanning dependencies of target leastSquareFitting
  [ 50%] Building CXX object CMakeFiles/leastSquareFitting.dir/main.cpp.o
  [100%] Linking CXX executable leastSquareFitting
  Undefined symbols for architecture x86_64:
    "printMatrix(Matrix)", referenced from:
        _main in main.cpp.o
    "constructMatrix(int, std::__1::vector&lt;double, 
  std::__1::allocator&lt;double&gt; &gt;)", referenced from:
        _main in main.cpp.o
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see 
  invocation)
  make[3]: *** [leastSquareFitting] Error 1
  make[2]: *** [CMakeFiles/leastSquareFitting.dir/all] Error 2
  make[1]: *** [CMakeFiles/leastSquareFitting.dir/rule] Error 2
  make: *** [leastSquareFitting] Error 2
  </code></pre>
  
  <p>I tried to search this error online, but couldn't solve it based on what I found. Here is my code:</p>
  
  <p>main.cpp</p>
  
  <pre><code>#include "fullMatrix.h"
  #include &lt;cstdio&gt;
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  using namespace std;
  int main()
  {
      vector&lt;double&gt; value = {1.0,2.0,3.0,4.0};
      Matrix m = constructMatrix(2, value);
      printMatrix(m);
      return 0;
  }   
  </code></pre>
  
  <p>fullMatrix.cpp</p>
  
  <pre><code>#include "fullMatrix.h"
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include "cmath"
  #include &lt;cstdio&gt;
  using namespace std;
  
  
  Matrix constructMatrix(int size, vector&lt;double&gt; x) {
      //initiate variables of a matrix
      Matrix myMatrix;
      myMatrix.size = size;
      myMatrix.value = x;
      return myMatrix;
  }
  
  void printMatrix(Matrix matrix){
      // Loop through rows and columns to display all values
      for (int row = 0; row &lt; matrix.size; row++) {
          for (int col = 0; col &lt; matrix.size; col++) {
              cout &lt;&lt;matrix.value[col+row*matrix.size] &lt;&lt; " ";
          }
          cout &lt;&lt; endl;
      }
  }
  </code></pre>
  
  <p>fullMatrix.h</p>
  
  <pre><code>#ifndef fullMatrix_h
  #define fullMatrix_h
  #include &lt;vector&gt;
  using namespace std;
  
  struct Matrix
  {
      int size;
      vector&lt;double&gt; value;
  };
  Matrix constructMatrix(int size, vector&lt;double&gt; x);
  
  void printMatrix(Matrix matrix);
  
  #endif
  </code></pre>
  
  <p>I am very new to CMake, and this is what's in CMakeLists.txt:</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.10)
  project(leastSquareFitting)
  
  set(CMAKE_CXX_STANDARD 11)
  
  add_executable(leastSquareFitting main.cpp)
  </code></pre>
  
  <p>Thank you! Any help is appreciated!</p>