如何修改mingw使用的make文件,以便链接器输入是带有对象的文件?

时间:2016-07-20 21:19:58

标签: makefile mingw

我使用Visual Studio和VisualGDB,我有大约2000个.c文件 visualgdb提供了一些模板make文件。问题是如果文件太多我得到这个windows 10限制错误(命令太长)

 process_begin: CreateProcess(C:\SysGCC\mingw32\bin\g++.exe, C:/SysGCC/mingw32/bin/g++.exe -o Debug/WindowsProject2.exe -Wl,-gc-sections -Wl,--start-group Debug/Source.o Debug/thisIsAveryLongFilenameYesSir0.o Debug/thisIsAveryLongFilenameYesSir1.o Debug/thisIsAveryLongFilenameYesSir10.o Debug/thisIsAveryLongFilenameYesSir100.o Debug/thisIsAveryLongFilenameYesSir998.o 
 ....many files ...
 Debug/thisIsAveryLongFilenameYesSir999.o    -Wl,--end-group
1>  Makefile:137: recipe for target 'Debug/WindowsProject2.exe' failed
1>  -------------------------------------------------------------
1>  Command exited with code 2
1>  Executable: cmd.exe
1>  Arguments: /c "C:\SysGCC\mingw32\bin\mingw32-make.exe" -j8 CONFIG=Debug
1>  Directory: C:\Users\timo\Desktop\Study\Embedded\STM32\VisualGDB\WindowsProject2\WindowsProject2
1>VisualGDB : error : Command-line action failed

我从visualGDB生成的make file templae中找到了make命令

ifeq ($(TARGETTYPE),SHARED)
$(BINARYDIR)/$(TARGETNAME): $(all_objs) $(EXTERNAL_LIBS)
    $(LD) -shared -o $@ $(LDFLAGS) $(START_GROUP) $(all_objs) $(LIBRARY_LDFLAGS) $(END_GROUP)
endif

支持人员给了我两个不起作用的变种:

1

ifeq ($(TARGETTYPE),APP)
$(BINARYDIR)/$(TARGETNAME): $(all_objs) $(EXTERNAL_LIBS)
 @echo $(all_objs) > $@.in
 $(LD) -o $@ $(LDFLAGS) $(START_GROUP) @$@.in $(LIBRARY_LDFLAGS) $(END_GROUP)
endif

2

ifeq ($(TARGETTYPE),APP)
$(BINARYDIR)/$(TARGETNAME): $(all_objs) $(EXTERNAL_LIBS)
<TAB>@echo -g > $@.in
<TAB>$(foreach obj,$(all_objs),cmd /c “echo $(obj) >> $@.in”)
<TAB> $(LD) -o $@ $(LDFLAGS) $(START_GROUP) @$@.in $(LIBRARY_LDFLAGS) $(END_GROUP)
endif

变体1有17_01_Dev.exe.in,其中包含对象列表,如

Debug / file2.o Debug / file1.o ...

但它仅限于aprox 8190个字符,然后它会删除所有其他对象

请帮助:(

1 个答案:

答案 0 :(得分:1)

Finnaly它适用于此!

ifeq ($(TARGETTYPE),APP)
$(BINARYDIR)/$(TARGETNAME): $(all_objs) $(EXTERNAL_LIBS)
    $(file >$@.in,$^)
    $(LD) -o $@ $(LDFLAGS) $(START_GROUP) @$@.in $(LIBRARY_LDFLAGS) $(END_GROUP)
endif