title: Another undefined reference to class::function in c++
body: <p>I keep coming across this common error then compiling my program. I've already tried many of the suggestions on the internet but none have worked so far. I've tried compiling my code using g++ via CMD and Code::Blocks, but both come up with the same error:</p>
  
  <pre class="lang-c++ prettyprint-override"><code>C:\Users\Damian\Desktop\test program.cpp|17|undefined reference to `level1::segout(int, double, double)'
  </code></pre>
  
  <p>I've tried compiling in CMD using all the cpp files:</p>
  
  <pre class="lang-batch prettyprint-override"><code>g++ "main program.cpp" "level1.cpp" -o "test.exe"
  </code></pre>
  
  <p>Here is my code below... maybe I am missing something obvious. It's been a while since I did C/C++ coding.</p>
  
  <p>main program.cpp</p>
  
  <pre class="lang-c++ prettyprint-override"><code>#define _USE_MATH_DEFINES
  
  #include &lt;iostream&gt;
  #include &lt;C:\Users\Damian\Desktop\level1.h&gt;
  #include &lt;string&gt;
  #include &lt;math.h&gt;
  using namespace std;
  
  int main()
  {
      double pitch = 0;
      double yaw = 0;
      cout &lt;&lt; "Low-Level Test Program\nPlease enter the pitch value (in degrees):\n";
      cin &gt;&gt; pitch;
      cout &lt;&lt; "Please enter the yaw value (in degrees):\n";
      cin &gt;&gt; yaw;
      level1::segout(0, pitch * (M_PI/180), yaw * (M_PI/180));
      return 0;
  }
  </code></pre>
  
  <p>level1.h</p>
  
  <pre class="lang-c++ prettyprint-override"><code>//all dimensions in MM, all angles in RADIANS
  
  #pragma once
  
  class level1 {
          static const double LENGTH_NEUTRAL, ANGLE_MAX, RADIUS, WIRE_RADIUS, ENCODER_RES;
          double L1, L2, L3;
      public:
          static void segout(int, double, double);
  };
  </code></pre>
  
  <p>level1.cpp</p>
  
  <pre class="lang-c++ prettyprint-override"><code>#define _USE_MATH_DEFINES
  
  #include &lt;iostream&gt;
  #include &lt;math.h&gt;
  #include &lt;stdlib.h&gt;
  //#include &lt;level0.h&gt; --not implemented yet
  using namespace std;
  
  const double LENGTH_NEUTRAL = 30;
  const double ANGLE_MAX = M_PI/4;
  const double RADIUS = 16;
  const double WIRE_RADIUS = 0.1;
  const double ENCODER_RES = (2*M_PI)/64;
  
  void segout(int Seg, double P, double Y)
  {
      //work area check
      if (sqrt(pow(P, 2) + pow(Y, 2)) &lt;= LENGTH_NEUTRAL + ANGLE_MAX)
      {
          cout &lt;&lt; "ERROR (0001): Specified coordinates are outside work area.\n";
          return;
      }
  
      //conversion
  
      //stage 1
      double L1 = LENGTH_NEUTRAL * (1 - ((sqrt(pow(P, 2) + pow(Y, 2)))/LENGTH_NEUTRAL) * RADIUS * sin((M_PI/2)+atan2(P, Y)));
  
      double L2 = LENGTH_NEUTRAL * (1 + ((sqrt(pow(P, 2) + pow(Y, 2)))/LENGTH_NEUTRAL) * RADIUS * sin((5*M_PI/6)+atan2(P, Y)));
  
      double L3 = LENGTH_NEUTRAL * (1 + ((sqrt(pow(P, 2) + pow(Y, 2)))/LENGTH_NEUTRAL) * RADIUS * cos((2*M_PI/3)+atan2(P, Y)));
  
      //stage 2
      L1 = labs((sqrt((L1 * sqrt(4 * pow(LENGTH_NEUTRAL, 2)+ pow(L1, 2)))/(pow(WIRE_RADIUS, 2)) - (pow(L1, 2))/(pow(WIRE_RADIUS, 2)))/sqrt(2)) / ENCODER_RES);
  
      L2 = labs((sqrt((L2 * sqrt(4 * pow(LENGTH_NEUTRAL, 2)+ pow(L2, 2)))/(pow(WIRE_RADIUS, 2)) - (pow(L2, 2))/(pow(WIRE_RADIUS, 2)))/sqrt(2)) / ENCODER_RES);
  
      L3 = labs((sqrt((L3 * sqrt(4 * pow(LENGTH_NEUTRAL, 2)+ pow(L3, 2)))/(pow(WIRE_RADIUS, 2)) - (pow(L3, 2))/(pow(WIRE_RADIUS, 2)))/sqrt(2)) / ENCODER_RES);
  
      //output
      //temp output for debugging
      cout &lt;&lt; "-------\nResults:\n";
      cout &lt;&lt; "L1: " &lt;&lt; L1 &lt;&lt; "\n";
      cout &lt;&lt; "L2: " &lt;&lt; L2 &lt;&lt; "\n";
      cout &lt;&lt; "L3: " &lt;&lt; L3 &lt;&lt; "\n";
  }
  </code></pre>
  
  <p>Here's an inexhaustive list of the things I've tried so far:</p>
  
  <ul>
  <li>Changing level1 from a static class to a normal class (so I have to create an object for it to work)</li>
  <li>Including the desktop in the search paths</li>
  <li>Compiling level1 to an object first and then compiling it with the main program.</li>
  <li>Turning on Linker AND/OR Compile for the header file in Code::Blocks</li>
  <li>Putting a level1.h #include header in level1.cpp</li>
  </ul>
  
  <p>There's probably a few more, but's it's late and my memory's going... thanks very much in advance for your help. </p>