Sometimes linker errors are issued for C source files with inlined functions. The error messages are:
This technical note discusses how to resolve this situation.
The linker error is issued because the compiler cannot fulfill some basic conditions (for inlined functions). In other words, check the following points and change the C source accordingly:
// To be present in a .h file (for example foo.h),
// typically included by many .c files.
inline unsigned char foo(unsigned char c)
{
return (c+1);
}
// To be present in precisely one (1) .c file
// (for example foo.c)
extern inline unsigned char foo(unsigned char c);
The reasons for P.1 and P.2 are straightforward. But the reason for P.3 can be harder to understand. From the ISO standard for C: '...An inline definition does not provide an external definition for the function...' So the extern declaration (from P.3) is used (by the linker) to resolve any non-inlined references to the function.
There are constrains C source code that contains inlined functions. For example, make sure that the inlined function does not refer to any static symbols (neither variables nor functions).
For more information, see Inlining functions (in the Development guide or in the Compiler reference guide).
All product names are trademarks or registered trademarks of their respective owners.
© IAR Systems 1995-2021 - All rights reserved.
We use cookies on this website to provide you with a better experience. You need to accept cookies to continue using this site. Cookies