7 years, 9 months ago.

BLE_iBeacon compilation error on Ubuntu | undefined reference to `__wrap__malloc_r'

I sucessfully desktop compiled and ran Blinky example on nRF51822 using https://launchpad.net/gcc-arm-embedded compiler. However, trying the BLE_iBeacon project I ran into issues.

This is what I get:

ignas@ignas-VirtualBox:~/Downloads/BLE_iBeacon$ make
arm-none-eabi-gcc -Wl,--gc-sections -Wl,--wrap,main -Wl,--wrap,_malloc_r -Wl,--wrap,_free_r -Wl,--wrap,_realloc_r -mcpu=cortex-m0 -mthumb --specs=nano.specs  -T.././mbed/TARGET_HRM1017/TOOLCHAIN_GCC_ARM/NRF51822.ld -L.././mbed/TARGET_HRM1017/TOOLCHAIN_GCC_ARM  -o BLE_iBeacon.elf nRF51822/nrf51-sdk/source/nordic_sdk/components/ble/ble_radio_notification/ble_radio_notification.o nRF51822/nrf51-sdk/source/nordic_sdk/components/ble/ble_services/ble_dfu/ble_dfu.o nRF51822/nrf51-sdk/source/nordic_sdk/components/libraries/util/sdk_mapped_flags.o nRF51822/nrf51-sdk/source/nordic_sdk/components/softdevice/common/softdevice_handler/softdevice_handler.o nRF51822/nrf51-sdk/source/nordic_sdk/components/softdevice/common/softdevice_handler/softdevice_handler_appsh.o main.o BLE_API/source/BLE.o BLE_API/source/DiscoveredCharacteristic.o BLE_API/source/GapScanningParams.o BLE_API/source/services/DFUService.o BLE_API/source/services/UARTService.o BLE_API/source/services/URIBeaconConfigService.o nRF51822/source/nRF5xCharacteristicDescriptorDiscoverer.o nRF51822/source/nRF5xDiscoveredCharacteristic.o nRF51822/source/nRF5xGap.o nRF51822/source/nRF5xGattClient.o nRF51822/source/nRF5xGattServer.o nRF51822/source/nRF5xServiceDiscovery.o nRF51822/source/nRF5xn.o nRF51822/source/btle/btle.o nRF51822/source/btle/btle_advertising.o nRF51822/source/btle/btle_discovery.o nRF51822/source/btle/btle_gap.o nRF51822/source/btle/btle_security.o nRF51822/source/btle/custom/custom_helper.o nRF51822/nrf51-sdk/source/nordic_sdk/components/ble/common/ble_conn_params.o ../mbed/TARGET_HRM1017/TOOLCHAIN_GCC_ARM/board.o ../mbed/TARGET_HRM1017/TOOLCHAIN_GCC_ARM/cmsis_nvic.o ../mbed/TARGET_HRM1017/TOOLCHAIN_GCC_ARM/retarget.o ../mbed/TARGET_HRM1017/TOOLCHAIN_GCC_ARM/startup_NRF51822.o ../mbed/TARGET_HRM1017/TOOLCHAIN_GCC_ARM/system_nrf51.o -Wl,--start-group -lmbed  -lstdc++ -lsupc++ -lm -lc -lgcc -lnosys -Wl,--end-group
/usr/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv6-m/libc_nano.a(lib_a-malloc.o): In function `malloc':
malloc.c:(.text.malloc+0x8): undefined reference to `__wrap__malloc_r'
/usr/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv6-m/libc_nano.a(lib_a-malloc.o): In function `free':
malloc.c:(.text.free+0x8): undefined reference to `__wrap__free_r'
/usr/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv6-m/libc_nano.a(lib_a-nano-svfprintf.o): In function `__ssputs_r':
nano-vfprintf.c:(.text.__ssputs_r+0x46): undefined reference to `__wrap__malloc_r'
nano-vfprintf.c:(.text.__ssputs_r+0x68): undefined reference to `__wrap__realloc_r'
nano-vfprintf.c:(.text.__ssputs_r+0x74): undefined reference to `__wrap__free_r'
/usr/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv6-m/libc_nano.a(lib_a-nano-svfprintf.o): In function `_svfiprintf_r':
nano-vfprintf.c:(.text._svfprintf_r+0x1a): undefined reference to `__wrap__malloc_r'
collect2: error: ld returned 1 exit status
make[1]: *** [BLE_iBeacon.elf] Error 1
make: *** [all] Error 2

Using Ubuntu 14.04. Tried different compiler versions, no go. Exported code for offline compilation (GCC (ARM Embedded)): https://developer.mbed.org/teams/Bluetooth-Low-Energy/code/BLE_iBeacon

Thanks for the help!

1 Answer

7 years, 8 months ago.

I had a similar issue moving some code into gcc.

I got a build by changing the Makefile to remove

-Wl,--wrap,_malloc_r -Wl,--wrap,_free_r -Wl,--wrap,_realloc_r

from LDFLAGS.

So, after you were able to build; were you able to run or debug the program on your target?

posted by Peter Foy 10 Jan 2018

I was able to program, certainly. I think I needed some makefile manipulation to get debug working, but my memory is vague as to what and there were lots of changes for other reasons. I'm pretty sure the non-debug code worked great out-of-the-box though.

posted by Stuart Tyrrell 10 Jan 2018