GCC makefile

This notebook could help somebody, like I needed it when I had started playing with mbed and GCC. If somebody just needs the most simple project with one makefile and mbed sources. Just clone git repo, build mbed library for GCC.

I published my makefile here: https://github.com/0xc0170/mbed_gcc_makefile

Current version: 2.0 What it brings: I have added all supported ARM GCC platforms (can be edited to use any other GCC toolchain).

I'll create another notebook how to use this makefile with eclipse and KL25Z to build and debug offline, straight from git repository.

To report a problem, leave a comment, or add an issue on github.


8 comments on GCC makefile:

17 Apr 2014

Hello Martin,

I've been playing around with this makefile attempting to get an offline compiler working. I followed the directions on your blog, but unfortunately I'm a bit stuck. First, I found that I needed to add a few directories to INC_DIRS. Namely (for KL25Z)

include directories

# directories
INC_DIRS = mbed mbed/$(TARGET_BOARD) mbed/$(TARGET_BOARD)/TOOLCHAIN_GCC_ARM
# app headers directories (remove comment and add more files)
INC_DIRS += mbed/$(TARGET_BOARD)/TARGET_Freescale/TARGET_KLXX
INC_DIRS += mbed/$(TARGET_BOARD)/TARGET_Freescale/TARGET_KLXX/TARGET_KL25Z

SRC_DIRS = mbed mbed/$(TARGET_BOARD) mbed/$(TARGET_BOARD)/TOOLCHAIN_GCC_ARM .
# app source directories (remove comment and add more files)
SRC_DIRS += mbed/$(TARGET_BOARD)/TARGET_Freescale/TARGET_KLXX
SRC_DIRS += mbed/$(TARGET_BOARD)/TARGET_Freescale/TARGET_KLXX/TARGET_KL25Z

However, it still is not compiling correctly for me. Here is the error I'm getting:

Eclipse Error

make all 
Building file: main.o
Invoking: MCU C++ Compiler
arm-none-eabi-g++ -g -ggdb -Os -Wall -fno-strict-aliasing -fno-rtti -ffunction-sections -fdata-sections -fno-exceptions -fno-delete-null-pointer-checks -fmessage-length=0 -fno-builtin -mthumb -mcpu=cortex-m0 -MMD -MP -DTARGET_KL25Z -DTOOLCHAIN_GCC_ARM -DNDEBUG -MF build/main.d -I.  -Imbed  -Imbed/TARGET_KL25Z  -Imbed/TARGET_KL25Z/TOOLCHAIN_GCC_ARM  -Imbed/TARGET_KL25Z/TARGET_Freescale/TARGET_KLXX  -Imbed/TARGET_KL25Z/TARGET_Freescale/TARGET_KLXX/TARGET_KL25Z -std=gnu++98 -c main.cpp -o build/main.o
Finished building: main.o
 
Building target: build/mbed.elf
Invoking: MCU Linker
arm-none-eabi-gcc -mcpu=cortex-m0 -mthumb -Os -L mbed/TARGET_KL25Z/TOOLCHAIN_GCC_ARM -T mbed/TARGET_KL25Z/TOOLCHAIN_GCC_ARM/MKL25Z4.ld -I.  -Imbed  -Imbed/TARGET_KL25Z  -Imbed/TARGET_KL25Z/TOOLCHAIN_GCC_ARM  -Imbed/TARGET_KL25Z/TARGET_Freescale/TARGET_KLXX  -Imbed/TARGET_KL25Z/TARGET_Freescale/TARGET_KLXX/TARGET_KL25Z -specs=nano.specs -Wl,-Map=build/mbed.map,--gc-sections build/main.o   mbed/TARGET_KL25Z/TOOLCHAIN_GCC_ARM/cmsis_nvic.o mbed/TARGET_KL25Z/TOOLCHAIN_GCC_ARM/startup_MKL25Z4.o mbed/TARGET_KL25Z/TOOLCHAIN_GCC_ARM/retarget.o mbed/TARGET_KL25Z/TOOLCHAIN_GCC_ARM/system_MKL25Z4.o -lmbed -lstdc++ -lsupc++ -lm -lgcc -lc -lnosys -o build/mbed.elf
mbed/TARGET_KL25Z/TOOLCHAIN_GCC_ARM/libmbed.a(exit.o): In function `exit':
exit.c:(.text.exit+0x24): undefined reference to `mbed_die'
collect2: error: ld returned 1 exit status
make: *** [build/mbed.elf] Error 1

My main.cpp file is a simple blink program that complies and works on the online compiler. Thanks in advance for the help!

Chris

18 Apr 2014

Hello Chris,

thank you for reporting this problem. I haven't updated that makefile for a while. As a result, it's not up to date with the current mbed sources. I am going to look at it this weekend, will update it.

In the meantime, to quickly fix it, please look at MBED_OBJ, there are missing some "new" object files, so that could solve the error you are seeing.

Regards, 0xc0170

18 Apr 2014

Thanks Martin,

I just opened a pull request. There were two MBED_OBJ missing, and I've added them, with one in a conditional since it's not always present depending on the target. Added the other directories too. Maybe if I have some free time later I'll add the newer GCC-supported boards.

I tested compiling for each board, and none of them give errors, though I don't actually have a board in front of me at the moment so I can't test it on the chip until later today.

Thanks again, and have a good day, Chris

17 Aug 2014

Hello,

I have managed to setup ARM-GCC for Nucleo-F030R8 board using the above makefile by adding the enteries for the Nucleo board. Everything works as expected if-and-only-if the "nano.specs" argument is removed from the Makefile. Otherwise, it compiles OK, but doesnt execute on the board. Removing the "nano.specs" works perfectly but leads to huge size of the bin file. Can somebody help me fixing this issue ?

I have attached the Makefile for reference. /media/uploads/sumitskm/makefile.txt

11 Sep 2014

I tried to compile mbed for the NUCLEO-F401RE target and it worked fine. Then i tried to compile in eclipse using the same makefile that you provide for F030R8 and cannot get it to work. It compiles fine but does not run on the board. Any idea ?

28 Jan 2015

we 4 me i added this line and everything was ok. and it built successfully

28 Jan 2015

MBED_OBJ += $(MBED_DIR)/$(TARGET_BOARD)/TOOLCHAIN_GCC_ARM/board.o

11 Feb 2015

Just wanted to say thanks for making this available. It's been really helpful for me.

Please log in to post comments.