9 years, 2 months ago.

undefined reference to `__wrap_main' GCC Embedded

Hi,

I am attempting to build the simple Hello World example using GCC Arm Embedded (on OS X).

However I am getting the following errors using the 4_9-2014q4 version of the tools.

Anyone have a suggested fix for this error?

cmd

/my_path/gcc-arm-none-eabi-4_9-2014q4/bin/arm-none-eabi-g++ -mcpu=cortex-m3 -mthumb -c -g -fno-common -fmessage-length=0 -Wall -fno-exceptions -ffunction-sections -fdata-sections -fomit-frame-pointer -MMD -MP -DNDEBUG -Os -DTARGET_LPC1768 -DTARGET_M3 -DTARGET_CORTEX_M -DTARGET_NXP -DTARGET_LPC176X -DTARGET_MBED_LPC1768 -DTOOLCHAIN_GCC_ARM -DTOOLCHAIN_GCC -D__CORTEX_M3 -DARM_MATH_CM3 -DMBED_BUILD_TIMESTAMP=1421836907.2 -D__MBED__=1  -std=gnu++98 -fno-rtti -I. -I./mbed -I./mbed/LPC1768 -I./mbed/LPC1768/GCC_ARM  -o main.o main.cpp

/my_path/gcc-arm-none-eabi-4_9-2014q4/bin/arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wl,--gc-sections --specs=nano.specs -u _printf_float -u _scanf_float -Wl,--wrap,main -Wl,-Map=HelloWorld.map,--cref -T./mbed/LPC1768/GCC_ARM/LPC1768.ld -L./mbed/LPC1768/GCC_ARM  -o HelloWorld.elf main.o mbed/LPC1768/GCC_ARM/system_LPC17xx.o mbed/LPC1768/GCC_ARM/cmsis_nvic.o mbed/LPC1768/GCC_ARM/core_cm3.o mbed/LPC1768/GCC_ARM/startup_LPC17xx.o -lcapi -lmbed  -lstdc++ -lsupc++ -lm -lc -lgcc -lnosys -lcapi -lmbed  -lstdc++ -lsupc++ -lm -lc -lgcc -lnosys
/my_path/gcc-arm-none-eabi-4_9-2014q4/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7-m/crt0.o: In function `_start':
(.text+0x4a): undefined reference to `__wrap_main'
collect2: error: ld returned 1 exit status
make: *** [HelloWorld.elf] Error 1

Question relating to:

3 Answers

9 years, 2 months ago.

I just exported a HelloWorld sample to GCC (ARM Embedded) and it built without problems with the same version of the GNU toolchain. You might want to try updating your version of the mbed library in the online compiler and then re-export.

You are getting the above error because your linker command line is missing retarget.o but when I export the Makefile it has it specified correctly on the linker command line.

Hi Adam,

Could you possibly post your makefile here so I can inspect?

posted by Jacob Hansen 21 Jan 2015
9 years, 1 month ago.

Hi.

I was having the same issue with the very same version of the GCC ARM Tools, but under Windows.

As Adam said, if you right click on the "mbed" library icon in your project and select "Update...", then the exported project compiles fine. I hope this helps.

Cheers,

Luigi

9 years, 1 month ago.

Hi,

I'm facing the same issue simple by trying to export USBSerial_HelloWorld. Even after update "mbed" library, the export ZIP doesn't contains any "retarget.o". In fact, the mbed folder doesn't contains any TARGET_LPC1768/ folder like it was in earlier exports. It seems that folder structure changed a lot, and the new folder mbed/LPC1768/GCC_ARM/ only contains the following :

cmsis_nvic.o core_cm3.o libmbed.a LPC1768.ld startup_LPC17xx.o system_LPC17xx.o

I've try to copy retarget.o from older projects into this new folder, but then there was a lot of duplicate symbols against libmbed.a

UPDATE : I've redone the whole process, and it finally worked ... Maybe the export somehow get randomly buggy, because folder structure is back to previous, ie : mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/ instead of mbed/LPC1768/GCC_ARM/