2018-03-26 10:41 AM
I am trying to use C++ with the cube generated make file. It worked nicely when everything was just C. From what I have done so far, the makefile generated from cube is C only. I added flags for C++ and separated the sources, but I now get an error that says it cannot find main.cpp (which is the while I changed to cpp).
I get this error:
build/startup_stm32f446xx.o: In function `LoopFillZerobss':
/home/andrew/Desktop/Test/CLI/startup_stm32f446xx.s:113: undefined reference to `main'collect2: error: ld returned 1 exit statusMakefile:211: recipe for target 'build/CLI.elf' failedmake: *** [build/CLI.elf] Error 1so I am guessing that my makefile has some issues.
Here is my edited makefile.
Note that I am sort of doing this blind since I only have a partial clue (or no clue) at what i am doing. Engineer by Google at its finest (or worst).
##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [2.27.0] date: [Fri Mar 23 15:10:04 EDT 2018]########################################################################################################################### ------------------------------------------------
# Generic Makefile (based on gcc)## ChangeLog :# 2017-02-10 - Several enhancements + project update mode# 2015-07-22 - first version# ------------------------------------------------######################################
# target######################################TARGET = CLI####################################### building variables####################################### debug build?DEBUG = 1# optimizationOPT = -Og######################################## paths######################################## source pathSOURCES_DIR = \Drivers/CMSIS \Drivers \Application/User/Src \Application/User/Src/stm32f4xx_hal_msp.c \Application/User/Src/main.cpp \Application/User \Drivers/STM32F4xx_HAL_Driver \Application \Application/User/Src/stm32f4xx_it.c# firmware library path
PERIFLIB_PATH =# Build path
BUILD_DIR = build######################################
# source####################################### C sourcesC_SOURCES = \Src/stm32f4xx_hal_msp.c \Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c \Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c \Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c \Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c \Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c \/Src/system_stm32f4xx.c \Src/stm32f4xx_it.c \Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c \Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c \Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c \Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c \Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c \Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c \Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c \Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c \Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c \Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.cCXX_SOURCES = \
Src/main.cpp# ASM sources
ASM_SOURCES = \startup_stm32f446xx.s####################################### firmware library######################################PERIFLIB_SOURCES =######################################## binaries#######################################BINPATH = ~/local/gcc-arm-none-eabi-6-2017-q1-update/binPREFIX = arm-none-eabi-CC = $(BINPATH)/$(PREFIX)gccCXX = $(BINPATH)/$(PREFIX)g++AS = $(BINPATH)/$(PREFIX)gcc -x assembler-with-cppCP = $(BINPATH)/$(PREFIX)objcopyAR = $(BINPATH)/$(PREFIX)arSZ = $(BINPATH)/$(PREFIX)sizeHEX = $(CP) -O ihexBIN = $(CP) -O binary -S ######################################## CFLAGS######################################## cpuCPU = -mcpu=cortex-m4# fpu
FPU = -mfpu=fpv4-sp-d16# float-abi
FLOAT-ABI = -mfloat-abi=hard# mcu
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)# macros for gcc
# AS definesAS_DEFS =# C defines
C_DEFS = \-DUSE_HAL_DRIVER \-DSTM32F446xx# AS includesAS_INCLUDES =# C includes
C_INCLUDES = \-IInc \-IDrivers/STM32F4xx_HAL_Driver/Inc \-IDrivers/STM32F4xx_HAL_Driver/Inc/Legacy \-IDrivers/CMSIS/Device/ST/STM32F4xx/Include \-IDrivers/CMSIS/Include# compile gcc flagsASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sectionsCFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2endifCXXFLAGS += $(CFLAGS)
CXXFLAGS += -fabi-version=0CXXFLAGS += -fno-rttiCXXFLAGS += -fno-exceptionsCXXFLAGS += -fno-use-cxa-atexitCXXFLAGS += -fno-threadsafe-statics# C++ -- Warnings
CXXFLAGS += -Weffc++CXXFLAGS += -Wfloat-equalCXXFLAGS += -Wsign-promoCXXFLAGS += -Wzero-as-null-pointer-constantCXXFLAGS += -Wmissing-declarations CXXFLAGS += -Woverloaded-virtualCXXFLAGS += -Wsuggest-final-typesCXXFLAGS += -Wsuggest-final-methodsCXXFLAGS += -Wsuggest-overrideCXXFLAGS += -Wsuggest-attribute=pureCXXFLAGS += -Wsuggest-attribute=constCXXFLAGS += -Wsuggest-attribute=noreturnCXXFLAGS += -Wsuggest-attribute=formatCXXFLAGS += -Wmissing-format-attributeCXXFLAGS += -Wold-style-castCXXFLAGS += -WshadowCXXFLAGS += -Wuseless-castCXXFLAGS += -Wctor-dtor-privacyCXXFLAGS += -Wstrict-null-sentinel# Generate dependency information
CFLAGS += -MMD -MP -MF'$(@:%.o=%.d)' -MT'$(@:%.o=%.d)'######################################## LDFLAGS######################################## link scriptLDSCRIPT = STM32F446RETx_FLASH.ld# libraries
LIBS = -lc -lm -lnosys LIBDIR = LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections# default action: build all
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin######################################## build the application######################################## list of objectsOBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))vpath %.c $(sort $(dir $(C_SOURCES)))# list of ASM program objectsOBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))vpath %.s $(sort $(dir $(ASM_SOURCES)))$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
$(AS) -c $(CFLAGS) $< -o $@$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
$(CC) $(OBJECTS) $(LDFLAGS) -o $@ $(SZ) $@$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(HEX) $< $@ $(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR) $(BIN) $< $@ $(BUILD_DIR): mkdir $@#######################################
# clean up#######################################clean: -rm -fR .dep $(BUILD_DIR) ######################################## dependencies#######################################-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)# *** EOF ***
Thanks in advance!
2018-03-26 11:05 AM
You'd need to define main() in a linkable fashion without C++ name mangling
ie
extern 'C' int main(void)
{
// ...Your code
while(1); // don't allow exit
return(1);
}