AnsweredAssumed Answered

Cube generated Makefile with c++

Question asked by Andrew C on Mar 26, 2018
Latest reply on Mar 26, 2018 by Clive One

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 status
Makefile:211: recipe for target 'build/CLI.elf' failed
make: *** [build/CLI.elf] Error 1

 

so 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
# optimization
OPT = -Og


#######################################
# paths
#######################################
# source path
SOURCES_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 sources
C_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.c

CXX_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/bin
PREFIX = arm-none-eabi-
CC = $(BINPATH)/$(PREFIX)gcc
CXX = $(BINPATH)/$(PREFIX)g++
AS = $(BINPATH)/$(PREFIX)gcc -x assembler-with-cpp
CP = $(BINPATH)/$(PREFIX)objcopy
AR = $(BINPATH)/$(PREFIX)ar
SZ = $(BINPATH)/$(PREFIX)size
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S

#######################################
# CFLAGS
#######################################
# cpu
CPU = -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 defines
AS_DEFS =

# C defines
C_DEFS = \
-DUSE_HAL_DRIVER \
-DSTM32F446xx


# AS includes
AS_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 flags
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections

CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections

ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2
endif

CXXFLAGS += $(CFLAGS)
CXXFLAGS += -fabi-version=0
CXXFLAGS += -fno-rtti
CXXFLAGS += -fno-exceptions
CXXFLAGS += -fno-use-cxa-atexit
CXXFLAGS += -fno-threadsafe-statics

# C++ -- Warnings
CXXFLAGS += -Weffc++
CXXFLAGS += -Wfloat-equal
CXXFLAGS += -Wsign-promo
CXXFLAGS += -Wzero-as-null-pointer-constant
CXXFLAGS += -Wmissing-declarations
CXXFLAGS += -Woverloaded-virtual
CXXFLAGS += -Wsuggest-final-types
CXXFLAGS += -Wsuggest-final-methods
CXXFLAGS += -Wsuggest-override
CXXFLAGS += -Wsuggest-attribute=pure
CXXFLAGS += -Wsuggest-attribute=const
CXXFLAGS += -Wsuggest-attribute=noreturn
CXXFLAGS += -Wsuggest-attribute=format
CXXFLAGS += -Wmissing-format-attribute
CXXFLAGS += -Wold-style-cast
CXXFLAGS += -Wshadow
CXXFLAGS += -Wuseless-cast
CXXFLAGS += -Wctor-dtor-privacy
CXXFLAGS += -Wstrict-null-sentinel

# Generate dependency information
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)"


#######################################
# LDFLAGS
#######################################
# link script
LDSCRIPT = 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 objects
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
vpath %.c $(sort $(dir $(C_SOURCES)))
# list of ASM program objects
OBJECTS += $(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!

Outcomes