make collect2.exe: error: ld returned 1 exit status error



我有这个makefile,当我用make cygwin编译时,它说:Make: collect2.exe: error: ld returned 1 exit status

######################################
# target
######################################
TARGET = blinkingled

######################################
# building variables
######################################
# debug build?
#DEBUG = 1
# optimization
OPT = -Og

#######################################
# paths
#######################################
# Build path
BUILD_DIR = build
######################################
# source
######################################
# C sources
SRCS      = main_cm0plus.c
SRCS      += system_tviibe1m_cm0plus.c
SRCS      += startup.c
SRCS      += $(wildcard src/drivers/adc/*.c)
SRCS      += $(wildcard src/drivers/canfd/*.c)
SRCS      += $(wildcard src/drivers/cpu/*.c)
SRCS      += $(wildcard src/drivers/crypto/*.c)
SRCS      += $(wildcard src/drivers/dma/*.c)
SRCS      += $(wildcard src/drivers/evtgen/*.c)
SRCS      += $(wildcard src/drivers/flash/*.c)
SRCS      += $(wildcard src/drivers/gpio/*.c)
SRCS      += $(wildcard src/drivers/ipc/*.c)
SRCS      += $(wildcard src/drivers/lin/*.c)
SRCS      += $(wildcard src/drivers/lvd/*.c)
SRCS      += $(wildcard src/drivers/mcwdt/*.c)
SRCS      += $(wildcard src/drivers/mpu/*.c)
SRCS      += $(wildcard src/drivers/prot/*.c)
SRCS      += $(wildcard src/drivers/scb/*.c)
SRCS      += $(wildcard src/drivers/smartio/*.c)
SRCS      += $(wildcard src/drivers/srom/*.c)
SRCS      += $(wildcard src/drivers/sysclk/*.c)
SRCS      += $(wildcard src/drivers/sysflt/*.c)
SRCS      += $(wildcard src/drivers/sysint/*.c)
SRCS      += $(wildcard src/drivers/syslib/*.c)
SRCS      += $(wildcard src/drivers/syspm/*.c)
SRCS      += $(wildcard src/drivers/sysreset/*.c)
SRCS      += $(wildcard src/drivers/sysrtc/*.c)
SRCS      += $(wildcard src/drivers/systick/*.c)
SRCS      += $(wildcard src/drivers/syswdt/*.c)
SRCS      += $(wildcard src/drivers/tcpwm/*.c)
SRCS      += $(wildcard src/drivers/trigmux/*.c)
SRCS      += $(wildcard src/interrupts/rev_d/*.c)
SRCS      += $(wildcard src/mw/button/*.c)
SRCS      += $(wildcard src/mw/flash/*.c)
SRCS      += $(wildcard src/semihosting/*.c)
SRCS      += $(wildcard src/swtimer/*.c)
SRCS      += $(wildcard src/startup/*.c)
SRCS      += $(wildcard src/system/*.c)
# ASM sources
ASM_SOURCES =  "C:/data/traveo/TVII_Sample_Driver_Library_7.1.0/tviibe1m/src/startup_cm0plus.s"
#startup_cm0plus.s 

#######################################
# binaries
#######################################
PREFIX = arm-none-eabi-
# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx)
# either it can be added to the PATH environment variable.
ifdef GCC_PATH
CC = $(GCC_PATH)/$(PREFIX)gcc
AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp
CP = $(GCC_PATH)/$(PREFIX)objcopy
SZ = $(GCC_PATH)/$(PREFIX)size
else
CC = $(PREFIX)gcc
AS = $(PREFIX)gcc -x assembler-with-cpp
CP = $(PREFIX)objcopy
SZ = $(PREFIX)size
endif
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S

#######################################
# CFLAGS
#######################################
# cpu
CPU = -mcpu=cortex-m0plus
# fpu
FPU = -mfpu=fpv4-sp-d16
# float-abi
FLOAT-ABI = -mfloat-abi=soft
# mcu
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
# macros for gcc
# AS defines
AS_DEFS = 
# C defines
#C_DEFS = ../../

# AS includes
AS_INCLUDES = 
# C includes
INCDIRS = ../../common/hdr
INCDIRS += ../../common/hdr/cmsis/include
INCDIRS += ../../common/src/drivers
INCDIRS += ../../common/src/drivers/sysclk
INCDIRS += ../../common/src/drivers/flash
INCDIRS += ../../common/src/drivers/syslib
INCDIRS += ../../common/src/drivers/mcwdt
INCDIRS += ../../tviibe1m/hdr/rev_d
INCDIRS += ../../tviibe1m/hdr/rev_d/ip
INCDIRS += ../../tviibe1m/src/system/rev_d
INCDIRS += ../../tviibe1m/hdr/rev_d/mcureg
INCDIRS += ../../tviibe1m/src/drivers/
INCDIRS += ../../common/src/drivers/syswdt
INCDIRS += ../../common/src/mw
INCLUDE   = $(addprefix -I,$(INCDIRS))
# 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
# My C flags:
CFLAGS += -Wno-unused-variable
# Generate dependency information
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"

#######################################
# LDFLAGS
#######################################
# link script
LDSCRIPT = "c:/data/traveo/TVII_Sample_Driver_Library_7.1.0/tviibe1m/src/linker.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: $(TARGET)
blinkingled: main_cm0plus.o system_tviibe1m_cm0plus.o startup.o
$(CC) $^ -o $@


main_cm0plus.o: main_cm0plus.c 
$(CC) $(CFLAGS) main_cm0plus.c

system_tviibe1m_cm0plus.o: system_tviibe1m_cm0plus.c cy_project.h cy_device_headers.h 
$(CC) $(CFLAGS) system_tviibe1m_cm0plus.c


startup.o: startup.c startup_customize.h
$(CC) $(CFLAGS) startup.c

BIN_NAME  = $(addprefix $(BUILD_DIR), $(TARGET))
.PHONY: all
all: $(BIN_NAME).elf
all: $(BIN_NAME).bin
all: $(BIN_NAME).s19
all: $(BIN_NAME).hex
all: $(BIN_NAME).lst
all: print_size

%.bin: %.elf
$(CP) -O binary -S $< $@
%.s19: %.elf
$(CP) -O srec -S $< $@
%.hex: %.elf
$(OBJCOPY) -O ihex -S $< $@
%.lst: %.elf
$(CP) -d $< > $@
.PHONY: print_size
print_size: $(BIN_NAME).elf
$(SIZE) $<

#######################################
# 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 $(BUILD_DIR)

#######################################
# dependencies
#######################################
-include $(wildcard $(BUILD_DIR)/*.d)
# *** EOF ***

错误:

c:/tools/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: c:/tools/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-no
ne-eabi/10.2.1/../../../../arm-none-eabi/lib/thumb/v6-m/nofplibc.a(lib_a-exit.o): in function `exit':
exit.c:(.text.exit+0x18): undefined reference to `_exit'
c:/tools/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: C:cygwin64tmpccHNkyd5.o: in function `main':
main_cm0plus.c:(.text.main+0x2): undefined reference to `SystemInit'
c:/tools/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: main_cm0plus.c:(.text.main+0xa): undefined reference to `Cy_SysEn
ableApplCore'
c:/tools/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: main_cm0plus.c:(.text.main+0x14): undefined reference to `Cy_GPIO
_Pin_Init'
c:/tools/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: main_cm0plus.c:(.text.main+0x1a): undefined reference to `Cy_SysT
ick_DelayInUs'
c:/tools/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: main_cm0plus.c:(.text.main+0x28): undefined reference to `__cm4_v
ector_base_linker_symbol'
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:173: main_cm0plus.o] Error 1

有人知道如何解决这个问题吗?我正试图从这个makefile生成一个十六进制和精灵。此外,我将感谢任何提示/更正我的制作文件。我正试图眨眼,但我很新的武装开发与makefiles由于

考虑一下:

all: blinkingled
blink: main_cm0plus.o system_tviibe1m_cm0plus.o startup.o
$(CC) main_cm0plus.o system_tviibe1m_cm0plus.o startup.o -o blinkingled

这里有两个规则定义了两个目标:all目标依赖于先决条件blinkingled,blink目标依赖于一堆目标文件。

当make调用blink目标时,它实际上创建了一个名为blinkingled的文件。这是错误的。Make只知道你在makefile中告诉它的内容,它没有办法知道你对你的食谱的用途撒了谎。如果您用一个名为blink的目标定义规则,那么make相信您提供给它的配方将创建一个名为blink的目标。

你需要改变你的配方,这样你才能说真话,使目标与构建的文件匹配:

blinkingled: main_cm0plus.o system_tviibe1m_cm0plus.o startup.o
$(CC) main_cm0plus.o system_tviibe1m_cm0plus.o startup.o -o blinkingled

现在一切都正常了。

更好的是在你的配方中使用make的自动变量,这样你就知道你正在创建make期望的目标(另外,DRY是一个伟大的编程原则):

blinkingled: main_cm0plus.o system_tviibe1m_cm0plus.o startup.o
$(CC) $^ -o $@

相关内容

最新更新