Handling ‘Undefined external’ message for inline function

Technical Note 49981






6/23/2020 2:52 PM


Sometimes linker errors are issued for C source files with inlined functions. The error messages are:

  • Error[e46]: Undefined external ... (from XLINK)
  • Error[Li005]: no definition for ... (from ILINK)

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:

  • The compiler must at compile-time be able to ‘see’ the definition of the inlined function.
  • If the inlined function is used in precisely one (1) .c file, move the definition to that .c file.
  • To use an inlined function in several .c files:

    1. Put the function definition in a .h file.
          // 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); 
    2. Include that .h file in all .c files where there is a call to the function.
    3. Make sure that there is precisely one (1) .c file with an extern declaration of the inlined function.
      // 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.

We do no longer support Internet Explorer. To get the best experience of iar.com, we recommend upgrading to a modern browser such as Chrome or Edge.