AnsweredAssumed Answered

JN5168 - when using assert I get undefined reference to _end

Question asked by Liam Hayes on Jan 22, 2016
Latest reply on Jan 28, 2016 by Earl Orlando Ramirez Sanchez

I've moved one of my projects from the old eclipse environment to BeyondStudio.


I am getting a linker error as shown below


c:/nxp/bstudio_nxp/sdk/tools/ba-elf-ba2-r36379/bin/../lib/gcc/ba-elf/4.7.4/../../../../ba-elf/lib/mcpu_jn51xx_sizeopt\libc.a(lib_a-glue.o): In function `_sbrk':

attempt to open c:/nxp/bstudio_nxp/sdk/tools/ba-elf-ba2-r36379/bin/../lib/gcc/ba-elf/4.7.4/../../../../ba-elf/lib/mcpu_jn51xx_sizeopt/ failed

/ba_toolchain/r36379/source/gcc-4.7.4-ba-r36379-build/ba-elf/mcpu_jn51xx_sizeopt/newlib/libc/sys/basim/../../../../../../../gcc-4.7.4-ba-r36379/newlib/libc/sys/basim/glue.c:75: undefined reference to `end'

attempt to open c:/nxp/bstudio_nxp/sdk/tools/ba-elf-ba2-r36379/bin/../lib/gcc/ba-elf/4.7.4/../../../../ba-elf/lib/mcpu_jn51xx_sizeopt\libc.a succeeded

/ba_toolchain/r36379/source/gcc-4.7.4-ba-r36379-build/ba-elf/mcpu_jn51xx_sizeopt/newlib/libc/sys/basim/../../../../../../../gcc-4.7.4-ba-r36379/newlib/libc/sys/basim/glue.c:75: undefined reference to `_stack'

/ba_toolchain/r36379/source/gcc-4.7.4-ba-r36379-build/ba-elf/mcpu_jn51xx_sizeopt/newlib/libc/sys/basim/../../../../../../../gcc-4.7.4-ba-r36379/newlib/libc/sys/basim/glue.c:75: undefined reference to `_stack'

/ba_toolchain/r36379/source/gcc-4.7.4-ba-r36379-build/ba-elf/mcpu_jn51xx_sizeopt/newlib/libc/sys/basim/../../../../../../../gcc-4.7.4-ba-r36379/newlib/libc/sys/basim/glue.c:75:(.text+0x197): relocation truncated to fit: R_BA_8 against undefined symbol `_stack'


The reason for this is a call the standard C assert (which is used for debugging purposes). Previously I had defined my own assert function which printed on the uart. If I leave that it in I get a redefinition error.

If you add #include <assert.h> and then assert(0) to the application template you can reproduce the problem.


The problem seems to be that the assert function in libc wants to call a full blown printf type function. These require memory control functions like malloc (hence the call to sbrk).

I can change my source code so it no longer uses standard assert (something like myassert) but I would like to understand why its doing this now?


Is there are version of libc that has 'simpler' printf or lets you define your own printf or assert?