我正在为stm32f4微编译器构建一个makefile,它包含所有外围库,并包含一个syscalls(名称newlib_stubs.cpp),其中printf()重定向到uart。在我开始将所有源代码构建到自己的目标文件以链接到可执行文件之前,我编写了makefile,以便在一次命中中编译所有源代码以证明makefile在此阶段工作但它不起作用。 这是makefile:
#name of application
TARGET = main
#name of target outputs
TARGET_ELF = $(TARGET).elf
TARGET_BIN = $(TARGET).bin
TARGET_HEX = $(TARGET).hex
# directories
CODE_DIR = code/
LIBRARY_DIR = library/
BUILD_DIR = build/
SOURCE_DIR = $(CODE_DIR)src/
STARTUP_DIR = $(LIBRARY_DIR)startup/
LINKER_DIR = $(LIBRARY_DIR)linker/
PERIPHERAL_DIR = $(LIBRARY_DIR)peripherals/
DEFAULT_DIR = $(LIBRARY_DIR)default/
OUTPUT_DIR = $(BUILD_DIR)output/
OBJECT_DIR = $(BUILD_DIR)objects/
#SOURCE_MAIN_DIR = $(CODE_DIR)src/
SOURCE_LIBRARY_DIR = $(PERIPHERAL_DIR)src/
SOURCE_PERIPHERAL_DIR = $(DEFAULT_DIR)src/
# files with paths attached
_C_FILES = $(wildcard $(SOURCE_DIR)*.c) # $(wildcard $(PERIPHERAL_DIR)src/*.c)
_C_DEFAULT_FILES = $(wildcard $(DEFAULT_DIR)src/*.c)
_C_PERIPHERAL_FILES = $(wildcard $(PERIPHERAL_DIR)src/*.c)
_CPP_FILES = $(wildcard $(SOURCE_DIR)*.cpp) # $(wildcard $(PERIPHERAL_DIR)src/*.cpp)
_CPP_DEFAULT_FILES = $(wildcard $(DEFAULT_DIR)src/*.cpp)
_CPP_PERIPHERAL_FILES = $(wildcard $(PERIPHERAL_DIR)src/*.cpp)
_STA_FILES = $(wildcard $(STARTUP_DIR)*.s)
_SRC_FILES = $(_CPP_FILES) $(_C_FILES) $(_C_DEFAULT_FILES) $(_C_PERIPHERAL_FILES) $(_CPP_DEFAULT_FILES) $(_CPP_PERIPHERAL_FILES) $(_STA_FILES)
_OBJ_FILES = $(addprefix $(OBJECT_DIR),$(notdir $(_CPP_FILES:.cpp=.o)))
_OBJ_FILES += $(addprefix $(OBJECT_DIR),$(notdir $(_C_FILES:.c=.o)))
_OBJ_FILES += $(addprefix $(OBJECT_DIR),$(notdir $(_CPP_DEFAULT_FILES:.cpp=.o)))
_OBJ_FILES += $(addprefix $(OBJECT_DIR),$(notdir $(_C_DEFAULT_FILES:.c=.o)))
_OBJ_FILES += $(addprefix $(OBJECT_DIR),$(notdir $(_CPP_PERIPHERAL_FILES:.cpp=.o)))
_OBJ_FILES += $(addprefix $(OBJECT_DIR),$(notdir $(_C_PERIPHERAL_FILES:.c=.o)))
_OBJ_FILES += $(addprefix $(OBJECT_DIR),$(notdir $(_STA_FILES:.s=.o)))
_LNK_FILES = $(wildcard $(LINKER_DIR)*.ld)
#file names without paths
C_FILES = $(_C_FILES:$(SOURCE_DIR)%=%)
C_DEFAULT_FILES = $(_C_DEFAULT_FILES:$(DEFAULT_DIR)src/%=%)
C_PERIPHERAL_FILES = $(_C_PERIPHERAL_FILES:$(PERIPHERAL_DIR)src/%=%)
CPP_FILES = $(_CPP_FILES:$(SOURCE_DIR)%=%)
CPP_DEFAULT_FILES = $(_CPP_DEFAULT_FILES:$(DEFAULT_DIR)src/%=%)
CPP_PERIPHERAL_FILES = $(_CPP_PERIPHERAL_FILES:$(PERIPHERAL_DIR)src/%=%)
STA_FILES = $(_STA_FILES:$(STARTUP_DIR)%=%)
SRC_FILES = $(CPP_FILES) $(C_FILES) $(STA_FILES) $(C_DEFAULT_FILES) $(C_PERIPHERAL_FILES)
SRC_FILES += $(CPP_DEFAULT_FILES) $(CPP_PERIPHERAL_FILES)
OBJ_FILES = $(_OBJ_FILES:$(OBJECT_DIR)%=%)
#include directories
HEADERS = $(CODE_DIR)inc/
HEADERS += $(LIBRARY_DIR)default/inc/
HEADERS += $(LIBRARY_DIR)peripherals/inc/
HEADERS +=
HEADERS +=
HEADERS +=
HEADERS +=
HEADERS +=
HEADERS +=
HEADERS +=
LIB_PATH =
#libraries to link
# Tool configuration
TOOLCHAIN = arm-none-eabi-
CC = $(TOOLCHAIN)gcc
CXX = $(TOOLCHAIN)g++
AS = $(TOOLCHAIN)gcc
LD = $(TOOLCHAIN)gcc
OBJCOPY = $(TOOLCHAIN)objcopy
# Architecture configuration
ARCH_FLAGS=-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16
# gcc compiler flags
CFLAGS += -O0 -ggdb3
CFLAGS += $(ARCH_FLAGS)
CFLAGS += -flto
CFLAGS += -ffunction-sections
CFLAGS += -fdata-sections
CFLAGS += $(foreach i, $(HEADERS), -I$(i))
# g++ compiler flags
CXXFLAGS = $(CFLAGS)
CXXFLAGS += -fno-rtti -fno-exceptions
CXXFLAGS += -std=c++11
# Flags for gcc as linker
LDFLAGS=$(ARCH_FLAGS)
LDFLAGS+=-Wl,--gc-sections
LDFLAGS+=$(foreach i, $(HEADERS), -L$(i))
LDFLAGS+=-T $(LDSCRIPT)
#.PHONY print
all:
$(CXX) $(CXXFLAGS) $(LDFLAGS) $(_SRC_FILES) -o $(TARGET_ELF)
print:
@echo name of application:
@echo TARGET = $(TARGET)
@echo name of target outputs
@echo TARGET_ELF = $(TARGET_ELF)
@echo TARGET_BIN = $(TARGET_BIN)
@echo TARGET_HEX = $(TARGET_HEX)
@echo
@echo directories
@echo CODE_DIR = $(CODE_DIR)
@echo LIBRARY_DIR = $(LIBRARY_DIR)
@echo BUILD_DIR = $(BUILD_DIR)
@echo SOURCE_DIR = $(SOURCE_DIR)
@echo STARTUP_DIR = $(STARTUP_DIR)
@echo LINKER_DIR = $(LINKER_DIR)
@echo OUTPUT_DIR = $(OUTPUT_DIR)
@echo OBJECT_DIR = $(OBJECT_DIR)
@echo
@echo files with paths attached:
@echo _C_FILES = $(_C_FILES)
@echo _C_DEFAULT_FILES = $(_C_DEFAULT_FILES)
@echo _C_PERIPHERAL_FILES = $(_C_PERIPHERAL_FILES)
@echo _CPP_FILES = $(_CPP_FILES)
@echo _CPP_DEFAULT_FILES = $(_CPP_DEFAULT_FILES)
@echo _CPP_PERIPHERAL_FILES = $(_CPP_PERIPHERAL_FILES)
@echo _STA_FILES = $(_STA_FILES)
@echo _SRC_FILES = $(_SRC_FILES)
@echo _OBJ_FILES = $(_OBJ_FILES)
@echo _LNK_FILES = $(_LNK_FILES)
@echo
@echo C_FILES = $(C_FILES)
@echo C_DEFAULT_FILES = $(C_DEFAULT_FILES)
@echo C_PERIPHERAL_FILES = $(C_PERIPHERAL_FILES)
@echo CPP_FILES = $(CPP_FILES)
@echo CPP_DEFAULT_FILES = $(CPP_DEFAULT_FILES)
@echo CPP_PERIPHERAL_FILES = $(CPP_PERIPHERAL_FILES)
@echo STA_FILES = $(STA_FILES)
@echo SRC_FILES = $(SRC_FILES)
@echo OBJ_FILES = $(OBJ_FILES)
此项目的来源可在此处找到:https://dl.dropboxusercontent.com/u/32204435/stm324f-discovery_template_28Dec2013.zip
这是我从编译器收到的输出:
nicholas@ASUS-G74Sx:~/Development/github/stm324f-discovery_template$ make
arm-none-eabi-g++ -O0 -ggdb3 -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -flto -ffunction-sections -fdata-sections -Icode/inc/ -Ilibrary/default/inc/ -Ilibrary/peripherals/inc/ -fno-rtti -fno-exceptions -std=c++11 -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--gc-sections -Lcode/inc/ -Llibrary/default/inc/ -Llibrary/peripherals/inc/ -T code/src/main.cpp library/default/src/stm32f4_discovery.c library/peripherals/src/misc.c library/peripherals/src/stm32f4xx_adc.c library/peripherals/src/stm32f4xx_can.c library/peripherals/src/stm32f4xx_crc.c library/peripherals/src/stm32f4xx_cryp_aes.c library/peripherals/src/stm32f4xx_cryp.c library/peripherals/src/stm32f4xx_cryp_des.c library/peripherals/src/stm32f4xx_cryp_tdes.c library/peripherals/src/stm32f4xx_dac.c library/peripherals/src/stm32f4xx_dbgmcu.c library/peripherals/src/stm32f4xx_dcmi.c library/peripherals/src/stm32f4xx_dma.c library/peripherals/src/stm32f4xx_exti.c library/peripherals/src/stm32f4xx_flash.c library/peripherals/src/stm32f4xx_fsmc.c library/peripherals/src/stm32f4xx_gpio.c library/peripherals/src/stm32f4xx_hash.c library/peripherals/src/stm32f4xx_hash_md5.c library/peripherals/src/stm32f4xx_hash_sha1.c library/peripherals/src/stm32f4xx_i2c.c library/peripherals/src/stm32f4xx_iwdg.c library/peripherals/src/stm32f4xx_pwr.c library/peripherals/src/stm32f4xx_rcc.c library/peripherals/src/stm32f4xx_rng.c library/peripherals/src/stm32f4xx_rtc.c library/peripherals/src/stm32f4xx_sdio.c library/peripherals/src/stm32f4xx_spi.c library/peripherals/src/stm32f4xx_syscfg.c library/peripherals/src/stm32f4xx_tim.c library/peripherals/src/stm32f4xx_usart.c library/peripherals/src/stm32f4xx_wwdg.c library/default/src/newlib_stubs.cpp library/default/src/stm32f4xx_it.cpp library/default/src/system_stm32f4xx.cpp library/startup/startup_stm32f4xx.s -o main.elf
/usr/bin/../lib/gcc/arm-none-eabi/4.8.3/../../../../arm-none-eabi/bin/ld:code/src/main.cpp:23: ignoring invalid character `#' in expression
/usr/bin/../lib/gcc/arm-none-eabi/4.8.3/../../../../arm-none-eabi/bin/ld:code/src/main.cpp:23: syntax error
collect2: error: ld returned 1 exit status
make: *** [all] Error 1
nicholas@ASUS-G74Sx:~/Development/github/stm324f-discovery_template$
main.cpp第0行到第30行:
/**
******************************************************************************
* @file main.c
* @author MCD Application Team
* @version V1.0.0
* @date 18-April-2011
* @brief Main program body
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_tim.h"
#include "stm32f4xx_syscfg.h"
#include "stm32f4xx_exti.h"
#include "stm32f4xx_dma.h"
#include "misc.h"
...
我无法识别main.cpp文件中的任何错误,而这些错误似乎来自于它们。
这个错误的包装是什么以及如何修复?
答案 0 :(得分:6)
您的Makefile设置LDFLAGS+=-T $(LDSCRIPT)
但未定义$ LDSCRIPT。这导致调用g++ -T {nothing here} main.cpp ...
,因此链接器假定main.cpp是脚本。尝试从Makefile中删除LDFLAGS+=-T $(LDSCRIPT)
。