I am currently coding in C with keil compiler. I am facing an issue I have to use inline function (performance matter in my case so I have to use it) and I have a file which contains an inline function. This inline function is declared in the header file and I try to access from another file which include the header. I always get : Undefined symbol error on the call of the function...

Here is the example to illustrate my issue :

File : test.h

extern void my_function (void);

File : test.c

#include "test.h"

__inline void my_function (void)
{
   printf("test ok\r\n");
}

File : main.c

#include "test.h"

int main (void)
{
    my_function ();
}

==> Linking error : Undefined symbol my_function

I could use macro instead, but do you know other alternative to fix my issue ?

有帮助吗?

解决方案

You can define the inline function in your header file:

File : test.h

static inline void my_function (void)
{
   printf("test ok\r\n");
}

其他提示

The solution to your problem is to define the inline function in the header file.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top