Reputation: 1305
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 ?
Upvotes: 3
Views: 3719
Reputation: 686
You can define the inline function in your header file:
File : test.h
static inline void my_function (void)
{
printf("test ok\r\n");
}
Upvotes: 4
Reputation: 33283
The solution to your problem is to define the inline function in the header file.
Upvotes: 2