7 years ago.

mbed_blinky fails to build on gcc -- undefined references to __wrap__*

I want to compile an mbed program using gcc. I tried the following steps and it did not work

1) In the on line compiler, I import "mbed_blinky", it works fine in that environment and I can make a LED blink.

2) I do "export program" and for good measure check the box to export all the files

3) On my Unbuntu 16 system, I see the compressed tar file. I unpack it and find there is a file called "Makefile"

4) I type "make". It compiles fine but does not link because of about a dozen undefined references to things called wrap* that appear to be wrappers around the normal malloc family of functions.

5) I check to see what version of arm gcc I have and get that it is current (see below)

chris@VM:mbed_blinky$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (15:4.9.3+svn231177-1) 4.9.3 20150529 (prerelease)
Copyright (C) 2014 Free Software Foundation, Inc.

6) Of course I try to "Google" this and I get MANY hits with others asking this question but no solutions. SURELY there must be a way to compile the "Hello World" program on a on current issue Ubuntu system.

7) BTW. I first tried this on my Apple Mac. Got the EXACT same errors. But I figured few others use Macs. So I fired up Ubuntu, did the apt-get upgrade and got the same result. So I doubt the problem is my development environment

Here is the copy/paste from the terminal

chris@VM:mbed_blinky$ make
Compile: main.cpp
link: mbed_blinky.elf
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/lib/armv7e-m/softfp/libc.a(lib_a-fflush.o): In function `__sflush_r':
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build/arm-none-eabi/armv7e-m/softfp/newlib/libc/stdio/../../../../../../../newlib/libc/stdio/fflush.c:198: undefined reference to `__wrap__free_r'
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/lib/armv7e-m/softfp/libc.a(lib_a-fclose.o): In function `_fclose_r':
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build/arm-none-eabi/armv7e-m/softfp/newlib/libc/stdio/../../../../../../../newlib/libc/stdio/fclose.c:109: undefined reference to `__wrap__free_r'
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build/arm-none-eabi/armv7e-m/softfp/newlib/libc/stdio/../../../../../../../newlib/libc/stdio/fclose.c:111: undefined reference to `__wrap__free_r'
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build/arm-none-eabi/armv7e-m/softfp/newlib/libc/stdio/../../../../../../../newlib/libc/stdio/fclose.c:107: undefined reference to `__wrap__free_r'
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/lib/armv7e-m/softfp/libc.a(lib_a-svfprintf.o): In function `_svfprintf_r':
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build/arm-none-eabi/armv7e-m/softfp/newlib/libc/stdio/../../../../../../../newlib/libc/stdio/vfprintf.c:882: undefined reference to `__wrap__malloc_r'
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/lib/armv7e-m/softfp/libc.a(lib_a-mprec.o): In function `_Balloc':
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build/arm-none-eabi/armv7e-m/softfp/newlib/libc/stdlib/../../../../../../../newlib/libc/stdlib/mprec.c:106: undefined reference to `__wrap__calloc_r'
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build/arm-none-eabi/armv7e-m/softfp/newlib/libc/stdlib/../../../../../../../newlib/libc/stdlib/mprec.c:123: undefined reference to `__wrap__calloc_r'
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/lib/armv7e-m/softfp/libc.a(lib_a-svfiprintf.o): In function `__ssprint_r':
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build/arm-none-eabi/armv7e-m/softfp/newlib/libc/stdio/../../../../../../../newlib/libc/stdio/vfprintf.c:312: undefined reference to `__wrap__malloc_r'
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build/arm-none-eabi/armv7e-m/softfp/newlib/libc/stdio/../../../../../../../newlib/libc/stdio/vfprintf.c:323: undefined reference to `__wrap__realloc_r'
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build/arm-none-eabi/armv7e-m/softfp/newlib/libc/stdio/../../../../../../../newlib/libc/stdio/vfprintf.c:327: undefined reference to `__wrap__free_r'
collect2: error: ld returned 1 exit status
/home/chris/Downloads/mbed_blinky/Makefile:331: recipe for target 'mbed_blinky.elf' failed
make[1]: *** [mbed_blinky.elf] Error 1
Makefile:25: recipe for target 'all' failed
make: *** [all] Error 2
chris@VM:mbed_blinky$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (15:4.9.3+svn231177-1) 4.9.3 20150529 (prerelease)
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Thanks for reading this far

Chris

2 Answers

7 years ago.

Hi Chris,

This is a "workflow bug" in our online tooling. It can take some time to convince the tools online that they should export very recent versions of mbed as mbed and not mbed-os. This generally only affects the most recent versions of mbed. As a workaround, you are free to remove the

-Wl,--wrap,_free_r

and similar from both the LD and LD_FLAGS variables.

We are working on an automatic mechanism to update the online tools knowledge of mbed releases when they happen.

Sorry for the inconvenience, -Jimmy

Accepted Answer
7 years ago.

Hi. Have you seen these ?

http://www.josho.org/blog/blog/2014/11/30/nucleo-gcc/

https://embeddist.wordpress.com/2015/05/21/how-to-build-arm-mbed-projects-on-gnu-tools-offline/

https://developer.mbed.org/handbook/Exporting-to-GCC-ARM-Embedded

and the last post here:

https://developer.mbed.org/forum/bugs-suggestions/topic/4228/

Thanks. I had only seen the links on the mbed site. The article at josho.org described the problem: The exporter creates broken Makefiles that need to be hand edited. His specific fixes did not work for me but now I know I need to look for some library that has wrap* in it and add it the LD_PATH.

posted by Chris Albertson 04 May 2017