Question

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 ?

Was it helpful?

Solution

You can define the inline function in your header file:

File : test.h

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top