When compiling a large Makefile project (Argument list too long) the suffix parameter is too long to solve the problem

When compiling a large project file with Makefile, the following error occurred, indicating that the parameter list is too long, and the gcc command suffix cannot exceed more than 8000 bytes.

By checking the data, the suffix list of gcc can be put into a file, and the Argument list too long can be solved by means of gcc @file.

Reference: 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.

Modify Makfile, redirect the location of the header file to a specific file, and then compile with 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))

Location of compiled files:

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

Although this can solve the problem, it only puts the path of .h into the file, and the path of .o file is not added to the file, and this way of writing is too verbose. If the following modifications are made, use the foreach function in the Makefile to cut the corresponding After the environment variable, redirect to the 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
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) 

After compiling again, the following error occurs:

gcc region `BMHDO‘ overflowed by xxx bytes

The reason for this is that the size of the firmware exceeds a specific size, modify the link script, my link script vLinkGen_Template.ld here, here is printed out through a specific environment variable LDFLAGS.

-T script is to specify the ld link script

Modify the linker script to increase the size of the 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 */
}

So far, the modification of the entire Makefile large-scale project has been completed.

Reference document: C Dialect Options (Using the GNU Compiler Collection (GCC))

Option Summary (Using the GNU Compiler Collection (GCC))

(37 messages) gcc @Commandfile solves the problem of too long commands_EarnForLive's Blog-CSDN Blog

(37 messages) PX4 firmware compilation problem region `flash' overflowed by 4253 bytes_gcc-arm-none-eabi-7.3.1_Caiyun's Note Blog-CSDN Blog

Guess you like

Origin blog.csdn.net/wanglei_11/article/details/129750488