How to use, but not disclose the built-in function in the c99 library?

I am writing a library in C99, and there are some parts of the library that will greatly benefit from using the macro / inline function. Built-in functions are better suited to my library.

However, in particular, I do not want to expose these built-in functions from the outside.

Everything works, but when I contact the library to create an executable, I get the error: "undefined reference to` na_impl_gfx__draw "

I reproduced the problem to a minimal test case that does exactly what I am doing:

lib.h:

void somefunc();

lib.c:

#include <stdio.h>
#include "lib.h"

inline void someinline(char *value);

void somefunc() {
  someinline("Hi!");
}

inline void someinline(char *value) {
  printf("%s\n", value);
}

main.c:

#include "lib.h"
int main(int argc, char *argv[]) {
  somefunc();
}

Now we compile:

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

It seems that when compiling the library, the built-in function is not replaced in the object code for the somefunc () function in lib.h

Why?

. , , , (Nb. , ).

? ?

+3
2

, , , .

, , static

inline static void someinline(char *value);

static:

inline static void someinline(char *value) {
  printf("%s\n", value);
}
+5

[, C, C99.]

, . , ".h". , .

, ( inline) ( extern inline) .

, lib.o, inline static . gcc , :

`-finline-       ,       (      ). ,       , .

 Enabled at level `-O2'.
+4

Source: https://habr.com/ru/post/1796577/


All Articles