title: Referencing C functions in static library from C++
body: <p>I have a static library of functions written in C.  Let's say the header file is called myHeader.h and looks like:</p>
  
  <pre><code>#ifndef MYHEADER_H
  #define MYHEADER_H
  
  void function1();
  void function2();
  
  #endif
  </code></pre>
  
  <p>function1 and function2 aren't anything too special.  Let's say they exist in a file called impl1.c which looks like:</p>
  
  <pre><code>#include "myHeader.h"
  
  void function1() {
      // code
  }
  void function2() {
      // more code
  }
  </code></pre>
  
  <p>All of the code mentioned so far is compiled into some static library called libMyLib.a.  I'd rather not modify any of the code used to build this library.  I also have a C++ header (cppHeader.h) that looks like:</p>
  
  <pre><code>#ifndef CPPHEADER_H
  #define CPPHEADER_H
  
  class CppClass {
      private:
          double attr1;
      public:
          void function3();
  };
  #endif
  </code></pre>
  
  <p>Then cppHeader.cpp looks like:</p>
  
  <pre><code>#include "cppHeader.h"
  #include "myHeader.h"
  
  // constructor
  CppClass::CppClass(){}
  
  void CppClass::function3() {
      function1();
  }
  </code></pre>
  
  <p>When I try to compile this, I get an error about an undefined reference to function1().  I believe that I've linked everything properly when compiling.  I'm pretty rusty in my C++.  I'm sure that I'm just doing something stupid.  I hope that my simple example code illustrates the problem well enough.</p>
  
  <p>Thanks in advance for any help!</p>