Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I use but not expose an inline function in a c99 library?
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload