title: Multiple definition of inline functions when linking static libs
body: <p>I have a C++ program that I compile with mingw (gcc for Windows).  Using the TDM release of mingw which includes gcc 4.4.1.  The executable links to two static library (.a) files:  On of them is a third-party library written in C; the other is a C++ library, written by me, that uses the C library provides my own C++ API on top.</p>
  
  <p>An (in my view, excessive) portion of the C library's functionality is implemented in inline functions.  You can't avoid including the inline functions when you use the C library's API, but when I try to link it all together, I'm getting link errors saying there is a multiple definition of all of the inline functions - both ones I have called in my C++ wrapper library and ones which I have not, basically anything defined inline in the headers has gotten a function created for it in both the C library and the C++ library.</p>
  
  <p>It doesn't cause multiple definition errors when the include files are used multiple times in different .c or .cpp files in the same project; the problem is just that it generates one definition per library.</p>
  
  <p>How/why is the compiler generating functions and symbols for these inline functions in both libraries?  How can I force it to stop generating them in my code?  Is there a tool I can run to strip the duplicate functions from the .a file, or a way to make the linker ignore multiple definitions?</p>
  
  <p>(FYI, the third party library does include #ifdef __cplusplus and extern "C" guards in all its headers; anyway if that were the problem, it would not cause a multiple definition of symbol, it would cause the opposite problem because the symbol would be undefined or at least different.)</p>
  
  <p>Notably, the link errors do NOT occur if I link to the third party C library's DLL; however then I get strange runtime failures that seem to have to do with my code having its own version of functions it should be calling from the DLL.  (As if the compiler is creating local versions of functions I didn't ask for.)</p>
  
  <p>Similar versions of this question have been asked before, however, I didn't find the answer to my situation in any of these:</p>
  
  <p>The answer to this question was that the poster was multiply defining <em>variables</em>, my problem is multiple definition of inline functions:  <a href="https://stackoverflow.com/questions/223771/repeated-multiple-definition-errors-from-including-same-header-in-multiple-cpps">Repeated Multiple Definition Errors from including same header in multiple cpps</a></p>
  
  <p>This was an MSVC program, but I'm using mingw; also, the poster's problem in this question was the definition of a C++ class constructor outside of the class body in a header, while my problem is with C functions that are inline:  <a href="https://stackoverflow.com/questions/717622/static-lib-multiple-definition-problem">Static Lib Multiple Definition Problem</a></p>
  
  <p>This fool renamed all his C code as C++ files and his C code wasn't C++-safe:  <a href="https://stackoverflow.com/questions/2208834/multiple-definition-of-lots-of-std-functions-when-linking">Multiple definition of lots of std:: functions when linking</a></p>
  
  <p>This one was just wanting to know why violating the one definition rule was not an error:  <a href="https://stackoverflow.com/questions/2025380/unpredictable-behavior-of-inline-functions-with-different-definitions">unpredictable behavior of Inline functions with different definitions</a></p>