title: c++ undefined references with static library
body: <p>I'm trying to make a static library from a class but when trying to use it, I always get errors with undefined references on anything. The way I proceeded was creating the object file like </p>
  
  <pre><code>g++ -c myClass.cpp -o myClass.o
  </code></pre>
  
  <p>and then packing it with </p>
  
  <pre><code>ar rcs myClass.lib myClass.o
  </code></pre>
  
  <p>There is something I'm obviously missing generally with this. I bet it's something with symbols.
  Thanks for any advice, I know it's most probably something I could find out if reading some tutorial so sorry if bothering with stupid stuff again :)</p>
  
  <h2>edit:</h2>
  
  <p>myClass.h:</p>
  
  <pre><code>class myClass{
      public:
          myClass();
          void function();
  };
  </code></pre>
  
  <p>myClass.cpp:</p>
  
  <pre><code>#include "myClass.h"
  
  myClass::myClass(){}
  void myClass::function(){}
  </code></pre>
  
  <p>program using the class:</p>
  
  <pre><code>#include "myClass.h"
  
  int main(){
  myClass mc;
  mc.function();
  
  return 0;
  }
  </code></pre>
  
  <p>finally I compile it like this:</p>
  
  <pre><code>g++ -o main.exe -L. -l myClass main.cpp
  </code></pre>
  
  <p>the error is just classic:</p>
  
  <pre><code>C:\Users\RULERO~1\AppData\Local\Temp/ccwM3vLy.o:main.cpp:(.text+0x31): undefined
   reference to `myClass::myClass()'
  C:\Users\RULERO~1\AppData\Local\Temp/ccwM3vLy.o:main.cpp:(.text+0x3c): undefined
   reference to `myClass::function()'
  collect2: ld returned 1 exit status
  </code></pre>