Undefined reference to `xxx` when linking

If you linking against the Redlib(none) C library variant and are using functions from the C library such as printf or malloc you will get errors about undefined references to symbols such as _Csyscall1, _sbrk and __sys_write when linking. Fuller examples of these error messages can be seen lower down this FAQ.

In such circumstances you will need to change which variant of the C library you are linking with to Redlib(nohost) or Redlib(semihost). Details of how to do this can be found in the FAQ Switching the selected C library.

For an explanation of the library variants, please see the FAQ What are none, nohost and semihost libraries?.

Another reason for seeing undefined references of course is that there is a problem with your own code base. For example, you may have mispelt the name of one of the functions that you call, or you may not have linked in a library project.

Finally, if you are extending the TI/Luminary examples to use C library functionality, please see the FAQ Extending LMI's examples to use C library functions.


Undefined References with Redlib (v1)

The below is an example set of errors encountered when linking an application that calls printf(), using the original Redlib (as shipped with Red Suite / LPCXpresso 3.6.x and earlier).

In function `__flsbuf':
_deferredlazyseek.c:(.text.(float, long, short, bool, float __restrict)+0x11c): undefined reference to `_Csyscall1'

In function `_ldexpl':
_ldexpl.c:(.text._ldexpl+0x34): undefined reference to `errno'
_ldexpl.c:(.text._ldexpl+0x3e): undefined reference to `errno'

In function `_Cwritebuf':
_writebuf.c:(.text._Cwritebuf+0x2a): undefined reference to `_Csyscall3'
_writebuf.c:(.text._Cwritebuf+0x46): undefined reference to `_Csyscall3'
_writebuf.c:(.text._Cwritebuf+0x74): undefined reference to `_Csyscall1'

In function `malloc':
alloc.c:(.text.malloc+0x98): undefined reference to `_sbrk'

In function `_Csysdie':
error.c:(.text._Csysdie+0x2c): undefined reference to `_Csyscall3'

In function `fseek':
fseek.c:(.text.fseek+0x2a): undefined reference to `_Csyscall1'
fseek.c:(.text.fseek+0xaa): undefined reference to `_Csyscall1'

In function `ftell':
ftell.c:(.text.ftell+0x42): undefined reference to `errno'
ftell.c:(.text.ftell+0x46): undefined reference to `errno'

In function `exit':
stdlib.c:(.text.exit+0x30): undefined reference to `_Csyscall1'

In function `fclose':
fclose.c:(.text.fclose+0x4c): undefined reference to `_Csyscall1'
fclose.c:(.text.fclose+0x72): undefined reference to `_Csys_tmpnam_'

In function `remove':
remove.c:(.text.remove+0x6): undefined reference to `_Csyscall1'


Undefined References with Redlib (v2)

The below is an example set of errors encountered when linking an application that calls printf(), using Redlib_v2 (as shipped with Red Suite 4.0 and LPCXpresso 3.7.x and later). For more information on Redlib_v2, please see the FAQ Notes on Redlib_v2.

In function `printf':
fpprintf.c:(.text.printf+0x36): undefined reference to `__sys_write'

In function `__flsbuf':
_deferredlazyseek.c:(.text.(float, long, short, bool, float __restrict)+0x92): undefined reference to `__sys_istty'

 In function `_Cwritebuf':
_writebuf.c:(.text._Cwritebuf+0x18): undefined reference to `__sys_flen'
_writebuf.c:(.text._Cwritebuf+0x2e): undefined reference to `__sys_seek'
_writebuf.c:(.text._Cwritebuf+0x56): undefined reference to `__sys_write'

In function `malloc':
alloc.c:(.text.malloc+0x70): undefined reference to `_sbrk'
alloc.c:(.text.malloc+0x92): undefined reference to `_sbrk'

In function `_Csys_alloc':
alloc.c:(.text._Csys_alloc+0xe): undefined reference to `__sys_write'
alloc.c:(.text._Csys_alloc+0x12): undefined reference to `__sys_appexit'

In function `fseek':
fseek.c:(.text.fseek+0x1c): undefined reference to `__sys_istty'
fseek.c:(.text.fseek+0x3e): undefined reference to `__sys_flen'

UndefinedReference (last edited 2011-06-13 19:15:36 by CrSupportAb)