Undefined reference to _sbrk_r for variadic arguments
Posted: Mon Oct 24, 2016 10:07 am
I'm using ChibiOS 16.1.4 on an STM32F303. I am attempting to use va_list, va_args, etc. in a function, but whenever I include <stdargs.h> and use those functions, I get the following linker errors:
/opt/homebrew-cask/Caskroom/gcc-arm-embedded/5_2-2015q4,20151219/gcc-arm-none-eabi-5_2-2015q4/bin/../lib/gcc/arm-none-eabi/5.2.1/../../../../arm-none-eabi/lib/armv7e-m/fpu/libg.a(lib_a-mallocr.o): In function `_malloc_r':
mallocr.c:(.text._malloc_r+0x232): undefined reference to `_sbrk_r'
mallocr.c:(.text._malloc_r+0x292): undefined reference to `_sbrk_r'
/opt/homebrew-cask/Caskroom/gcc-arm-embedded/5_2-2015q4,20151219/gcc-arm-none-eabi-5_2-2015q4/bin/../lib/gcc/arm-none-eabi/5.2.1/../../../../arm-none-eabi/lib/armv7e-m/fpu/libg.a(lib_a-freer.o): In function `_malloc_trim_r':
mallocr.c:(.text._malloc_trim_r+0x30): undefined reference to `_sbrk_r'
mallocr.c:(.text._malloc_trim_r+0x4a): undefined reference to `_sbrk_r'
mallocr.c:(.text._malloc_trim_r+0x72): undefined reference to `_sbrk_r'
I have included ChibiOS/os/various/syscalls.c in the Makefile. Without it, the error is much simpler:
/opt/homebrew-cask/Caskroom/gcc-arm-embedded/5_2-2015q4,20151219/gcc-arm-none-eabi-5_2-2015q4/bin/../lib/gcc/arm-none-eabi/5.2.1/../../../../arm-none-eabi/lib/armv7e-m/fpu/libg.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk'
I see _sbrk_r defined in syscalls.c, so why can it still not find it after I include it? If I delete all references to va_list, va_args, etc., the compiler is successful again. How can I use variadic arguments in ChibiOS? I know chprintf uses it, so it must be possible.
/opt/homebrew-cask/Caskroom/gcc-arm-embedded/5_2-2015q4,20151219/gcc-arm-none-eabi-5_2-2015q4/bin/../lib/gcc/arm-none-eabi/5.2.1/../../../../arm-none-eabi/lib/armv7e-m/fpu/libg.a(lib_a-mallocr.o): In function `_malloc_r':
mallocr.c:(.text._malloc_r+0x232): undefined reference to `_sbrk_r'
mallocr.c:(.text._malloc_r+0x292): undefined reference to `_sbrk_r'
/opt/homebrew-cask/Caskroom/gcc-arm-embedded/5_2-2015q4,20151219/gcc-arm-none-eabi-5_2-2015q4/bin/../lib/gcc/arm-none-eabi/5.2.1/../../../../arm-none-eabi/lib/armv7e-m/fpu/libg.a(lib_a-freer.o): In function `_malloc_trim_r':
mallocr.c:(.text._malloc_trim_r+0x30): undefined reference to `_sbrk_r'
mallocr.c:(.text._malloc_trim_r+0x4a): undefined reference to `_sbrk_r'
mallocr.c:(.text._malloc_trim_r+0x72): undefined reference to `_sbrk_r'
I have included ChibiOS/os/various/syscalls.c in the Makefile. Without it, the error is much simpler:
/opt/homebrew-cask/Caskroom/gcc-arm-embedded/5_2-2015q4,20151219/gcc-arm-none-eabi-5_2-2015q4/bin/../lib/gcc/arm-none-eabi/5.2.1/../../../../arm-none-eabi/lib/armv7e-m/fpu/libg.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk'
I see _sbrk_r defined in syscalls.c, so why can it still not find it after I include it? If I delete all references to va_list, va_args, etc., the compiler is successful again. How can I use variadic arguments in ChibiOS? I know chprintf uses it, so it must be possible.