Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 11 months ago.
[GNU Make] Offline Compiler: Undefined Reference Problem
In short: received "undefined reference" error while compiling an example code:
Compile Error
/usr/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: warning: cannot find entry symbol Reset_Handler; defaulting to 0000000008000000 main.o: In function `__static_initialization_and_destruction_0': /home/htsai/stmProjects/blink/../mbed/DigitalOut.h:49: undefined reference to `gpio_init_out' collect2: error: ld returned 1 exit status make: *** [blink.elf] Error 1
The code is exported from a very simple blink program for STM32_NUCLEO_F303RE:
main.cpp
#include "mbed.h" DigitalOut myled(LED1); int main() { while(1) { myled = 1; // LED is ON wait(0.2); // 200 ms myled = 0; // LED is OFF wait(1.0); // 1 sec } }
I copied the linker script (STM32F303XE_FLASH.ld) from official stm32cubeF3 because it doesn't come with mbed, and modified my Makefile as:
Makefile
# This file was automagically generated by mbed.org. For more information, # see http://mbed.org/handbook/Exporting-to-GCC-ARM-Embedded GCC_BIN = PROJECT = blink OBJECTS = ./main.o SYS_OBJECTS = INCLUDE_PATHS = -I. -I../mbed -I../mbed/TARGET_NUCLEO_F303RE -I../mbed/TARGET_NUCLEO_F303RE/TARGET_STM/TARGET_STM32F3 -I../mbed/TARGET_NUCLEO_F303RE/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303RE LIBRARY_PATHS = LIBRARIES = LINKER_SCRIPT = ../STM32F303XE_FLASH.ld ############################################################################### AS = $(GCC_BIN)arm-none-eabi-as CC = $(GCC_BIN)arm-none-eabi-gcc CPP = $(GCC_BIN)arm-none-eabi-g++ LD = $(GCC_BIN)arm-none-eabi-gcc OBJCOPY = $(GCC_BIN)arm-none-eabi-objcopy OBJDUMP = $(GCC_BIN)arm-none-eabi-objdump SIZE = $(GCC_BIN)arm-none-eabi-size ifeq ($(HARDFP),1) FLOAT_ABI = hard else FLOAT_ABI = softfp endif CPU = -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=$(FLOAT_ABI) CC_FLAGS = $(CPU) -c -g -fno-common -fmessage-length=0 -Wall -Wextra -fno-exceptions -ffunction-sections -fdata-sections -fomit-frame-pointer -MMD -MP CC_SYMBOLS = -DTARGET_RTOS_M4_M7 -DTARGET_FF_ARDUINO -DTOOLCHAIN_GCC_ARM -DTOOLCHAIN_GCC -DTARGET_STM32F303RE -DTARGET_CORTEX_M -D__FPU_PRESENT=1 -D__MBED__=1 -DTARGET_M4 -DTARGET_FF_MORPHO -DTARGET_STM -DMBED_BUILD_TIMESTAMP=1454081451.86 -DTARGET_NUCLEO_F303RE -DTARGET_STM32F3 -D__CORTEX_M4 -DARM_MATH_CM4 LD_FLAGS = $(CPU) -Wl,--gc-sections --specs=nano.specs -u _printf_float -u _scanf_float -Wl,--wrap,main -Wl,-Map=$(PROJECT).map,--cref LD_SYS_LIBS = -lstdc++ -lsupc++ -lm -lc -lgcc -lnosys ifeq ($(DEBUG), 1) CC_FLAGS += -DDEBUG -O0 else CC_FLAGS += -DNDEBUG -Os endif .PHONY: all clean lst size all: $(PROJECT).bin $(PROJECT).hex size clean: rm -f $(PROJECT).bin $(PROJECT).elf $(PROJECT).hex $(PROJECT).map $(PROJECT).lst $(OBJECTS) $(DEPS) .asm.o: $(CC) $(CPU) -c -x assembler-with-cpp -o $@ $< .s.o: $(CC) $(CPU) -c -x assembler-with-cpp -o $@ $< .S.o: $(CC) $(CPU) -c -x assembler-with-cpp -o $@ $< .c.o: $(CC) $(CC_FLAGS) $(CC_SYMBOLS) -std=gnu99 $(INCLUDE_PATHS) -o $@ $< .cpp.o: $(CPP) $(CC_FLAGS) $(CC_SYMBOLS) -std=gnu++98 -fno-rtti $(INCLUDE_PATHS) -o $@ $< $(PROJECT).elf: $(OBJECTS) $(SYS_OBJECTS) $(LD) $(LD_FLAGS) -T$(LINKER_SCRIPT) $(LIBRARY_PATHS) -o $@ $^ $(LIBRARIES) $(LD_SYS_LIBS) $(LIBRARIES) $(LD_SYS_LIBS) $(PROJECT).bin: $(PROJECT).elf $(OBJCOPY) -O binary $< $@ $(PROJECT).hex: $(PROJECT).elf @$(OBJCOPY) -O ihex $< $@ $(PROJECT).lst: $(PROJECT).elf @$(OBJDUMP) -Sdh $< > $@ lst: $(PROJECT).lst size: $(PROJECT).elf $(SIZE) $(PROJECT).elf DEPS = $(OBJECTS:.o=.d) $(SYS_OBJECTS:.o=.d) -include $(DEPS)
Toolchain is installed from terry.guo's repo with the following version information:
Toolchain Ver
$ arm-none-eabi-gcc --version arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.9.3 20150529 (release) [ARM/embedded-4_9-branch revision 227977] 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.
mbed library is directly cloned from default branch with mercury. No luck so far. I'll try this SDK in the next couple of hours. https://github.com/mbedmicro/mbed