在用Makefile编译大型项目文件时出现了如下错误,提示参数列表过长,gcc 命令后缀是不能超过8000多个字节猜测。
通过查资料gcc 的后缀列表可以放到一个文件中,通过gcc @file 的方式来解决 Argument list too long ,
参考依据:Overall Options (Using the GNU Compiler Collection (GCC))
@file
Read command-line options from file. The options read are inserted in place of the original @file option. If file does not exist, or cannot be read, then the option will be treated literally, and not removed.
Options in file are separated by whitespace. A whitespace character may be included in an option by surrounding the entire option in either single or double quotes. Any character (including a backslash) may be included by prefixing
the character to be included with a backslash. The file may itself contain additional @file options; any such options will be processed recursively.
修改Makfile,将头文件位置重定向到特定的文件中,再gcc @file 去编译:
#-----------------------------------------wl-------------------------add--------------
current_root_dir_temp1 = $(shell pwd)
current_root_dir_cover1 = $(subst \,/,$(current_root_dir_temp1))
current_root_dir1 = $(subst /cygdrive/c,C:,$(current_root_dir_cover1))
$(info "----------------------$(current_root_dir1)")
current_root_dir2 = "$(current_root_dir1)/iROMXX.ccompincludelist"
$(info "----------------------$(current_root_dir2)")
#add file path
#VCU APP
A = -I\"$(current_root_dir)/Source/App/SWC_VCU/AccPed \"
C := $(shell echo $A >> $(current_root_dir2))
A = -I\"$(current_root_dir)/Source/App/SWC_VCU/AccPedDev \"
C := $(shell echo $A >> $(current_root_dir2))
A = -I\"$(current_root_dir)/Source/App/SWC_VCU/ACCtl_TqDem \"
C := $(shell echo $A >> $(current_root_dir2))
A = -I\"$(current_root_dir)/Source/App/SWC_VCU/ActvDynWhlLd \"
C := $(shell echo $A >> $(current_root_dir2))
A = -I\"$(current_root_dir)/Source/App/SWC_VCU/AntiRollBack \"
C := $(shell echo $A >> $(current_root_dir2))
A = -I\"$(current_root_dir)/Source/App/SWC_VCU/AxleTqPreZrCrsng \"
C := $(shell echo $A >> $(current_root_dir2))
编译文件的位置:
#$(info "------wl------$(ATECH_USER_LINKFLAGS)")
$(info $(LDFLAGS));
.SECONDEXPANSION:
ifneq ($(LINK_LIBRARIES),1)
$(TARGET): $$(OBJS) $(LD_DEPENDENCIES) $(LINKER_COMMAND_FILE) \
$(ADDITIONAL_OBJECTS_U) $(ADDITIONAL_LIBRARIES_U) \
$(TARGET_LIBRARY) $(TARGET_RESPONSE_FILE) \
$(wildcard Makefile.project.part.defines) \
$(dir $(TARGET))/.dirstamp
@$(ECHO) "LD $@"
$(Q)$(CC_ENV) $(LD) $(LDFLAGS) $(LINKER_OBJS_ARG) \
$(ADDITIONAL_OBJECTS_U) \
$(ADDITIONAL_LIBRARIES_U) \
$(SYSLIBS) \
$(LD_REDIRECT_OUTPUT) \
@$(current_root_dir2) \
$(ATECH_USER_LINKFLAGS)
这样虽然能解决问题,但是只是将.h的路径放到文件中了,.o文件路径没增加到文件中,且这样写法过于啰嗦,如是有了以下修改,利用Makefile中的foreach函数切割对应的环境变量后,重定向到文件中:
#-----------------------------------------wl-------------------------add--------------
current_root_dir_temp1 = $(shell pwd)
current_root_dir_cover1 = $(subst \,/,$(current_root_dir_temp1))
current_root_dir1 = $(subst /cygdrive/c,C:,$(current_root_dir_cover1))
$(info "----------------------$(current_root_dir1)")
current_root_dir2 = "$(current_root_dir1)/iROMXX.ccompincludelist"
$(info "----------------------$(current_root_dir2)")
#add file path
#VCU APP
ATECH_INCLUDES := $(foreach dir1,$(ATECH_INCLUDE),$(shell echo $(dir1) >> $(current_root_dir2)))
#$(info "$(B)")
#-----------------------------------------wl-------------------------end--------------
current_root_dir3 = "$(current_root_dir1)/iROMXX.ccompincludelist2"
#C := $(shell echo $(LINKER_OBJS_ARG) >> $(current_root_dir3))
#WLLL := $(shell for var in echo ${LINKER_OBJS_ARG};do echo var >> $(current_root_dir3);done)
ATECH_OBJECTS := $(foreach dir,$(LINKER_OBJS_ARG),$(shell echo $(dir) >> $(current_root_dir3)))
.SECONDEXPANSION:
ifneq ($(LINK_LIBRARIES),1)
$(TARGET): $$(OBJS) $(LD_DEPENDENCIES) $(LINKER_COMMAND_FILE) \
$(ADDITIONAL_OBJECTS_U) $(ADDITIONAL_LIBRARIES_U) \
$(TARGET_LIBRARY) $(TARGET_RESPONSE_FILE) \
$(wildcard Makefile.project.part.defines) \
$(dir $(TARGET))/.dirstamp
@$(ECHO) "LD $@"
$(Q)$(CC_ENV) $(LD) $(LDFLAGS) @$(current_root_dir3) \
$(ADDITIONAL_OBJECTS_U) \
$(ADDITIONAL_LIBRARIES_U) \
$(SYSLIBS) \
$(LD_REDIRECT_OUTPUT) \
@$(current_root_dir2) \
$(ATECH_USER_LINKFLAGS)
再次编译后出现下面错误 :
gcc region `BMHDO‘ overflowed by xxx bytes
这个原因是固件大小超过了特定的大小,修改链接脚本,本人这里的链接脚本vLinkGen_Template.ld,,这里是通过特定的环境变量LDFLAGS打印出来的。
-T script 是指定ld链接脚本
修改链接脚本,增大BMHDO section 的大小:
MEMORY
{
DSPR_Core5 : ORIGIN = 0x10000000 , LENGTH = 0x00018000 /* 96 KiB */
DSPR_Core4 : ORIGIN = 0x30000000 , LENGTH = 0x00018000 /* 96 KiB */
DSPR_Core3 : ORIGIN = 0x40000000 , LENGTH = 0x00018000 /* 96 KiB */
DSPR_Core2 : ORIGIN = 0x50000000 , LENGTH = 0x00018000 /* 96 KiB */
DSPR_Core1 : ORIGIN = 0x60000000 , LENGTH = 0x0003C000 /* 240 KiB */
DSPR_Core0 : ORIGIN = 0x70000000 , LENGTH = 0x00032FF0 /* 204 KiB */
Variables_Shared : ORIGIN = 0x70032FF0 , LENGTH = 0x00000080 /* 16 Byte */
StartupStack_Shared : ORIGIN = 0x70033000 , LENGTH = 0x00009000 /* 36 KiB */
PFlash0_Boot_reserved : ORIGIN = 0x80000000 , LENGTH = 0x00060000 /* 384 KiB */
StartupCode_FirstExecInst : ORIGIN = 0x80060000 , LENGTH = 0x00000500 /* 1 KiB */
CoreExceptions_FirstExecInst : ORIGIN = 0x80060500 , LENGTH = 0x00000600 /* 512 Byte */
PFlash0_Cached : ORIGIN = 0x80060700 , LENGTH = 0x0029F900 /* 3 MiB */
PFlash1_Cached : ORIGIN = 0x80300000 , LENGTH = 0x002FFF00 /* 3 MiB */
PFlash1_Info_reserved : ORIGIN = 0x805FFF00 , LENGTH = 0x00000300 /* 256 Byte */
BMHD0 : ORIGIN = 0xAF400000 , LENGTH = 0x00000600 /* 512 Byte */
}
至此,完成对整个Makefile大型工程的修改。
参考文档:C Dialect Options (Using the GNU Compiler Collection (GCC))
Option Summary (Using the GNU Compiler Collection (GCC))
(37条消息) gcc @Commandfile解决命令过长问题_EarnForLive的博客-CSDN博客
(37条消息) PX4固件编译问题region `flash‘ overflowed by 4253 bytes_gcc-arm-none-eabi-7.3.1_彩云的笔记的博客-CSDN博客