title: How do I use but not expose an inline function in a c99 library?
body: <p>I'm writing a library in C99, and there are some parts of the library that would benefit significantly from the use of a macro / inline function. Inline functions are a better fit for my library.</p>
  
  <p>However, very specifically I do not want to externally expose these inline functions.</p>
  
  <p>Everything appears to work, but when I link against the library to create an executable I get the error: "undefined reference to `na_impl_gfx__draw'" </p>
  
  <p>I have reproduced the problem to a minimal test case which does exactly what I do:</p>
  
  <p>lib.h:</p>
  
  <pre><code>void somefunc();
  </code></pre>
  
  <p>lib.c:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include "lib.h"
  
  inline void someinline(char *value);
  
  void somefunc() {
    someinline("Hi!");
  }
  
  inline void someinline(char *value) {
    printf("%s\n", value);
  }
  </code></pre>
  
  <p>main.c:</p>
  
  <pre><code>#include "lib.h"
  int main(int argc, char *argv[]) {
    somefunc();
  }
  </code></pre>
  
  <p>Now we compile:</p>
  
  <pre><code>doug@Wulf:~/test$ gcc -c -std=c99 lib.c
  doug@Wulf:~/test$ gcc -c -std=c99 main.c
  doug@Wulf:~/test$ gcc -std=c99 lib.o main.o
  lib.o: In function `somefunc':
  lib.c:(.text+0xe): undefined reference to `someinline'
  lib.c:(.text+0x1a): undefined reference to `someinline'
  lib.c:(.text+0x26): undefined reference to `someinline'
  collect2: ld returned 1 exit status
  </code></pre>
  
  <p>It would appear that when compiling the library, the inline function is not being substituted into the object code for the function somefunc() in lib.h</p>
  
  <p>Why?</p>
  
  <p>The inline function is not externally visible. I would expect that when the library is compiled, the inline function is inlined into the function, just like the macro is (Nb. using only a macro this code compiles file).</p>
  
  <p>What am I doing wrong? Or is this a restriction of inline functions?</p>