Windows Command Line Limit

Windows has a limit to the number of characters that can be used in a single command on the command line.

In a large project with many files it becomes possible that a make variable exceeds the character limit.

OBJECTS := $(subst .cpp,.obj, $(SOURCES)) LINK $(OBJECTS) /out:$@

Imagine that Objects is more than 32767 characters in length. Running make will fail with the cryptic error make (e=87): The parameter is incorrect. When executing the link line, Windows tries to substitute in the value of the objects variable, but is only able to bring in the fraction that is within the character limit.

To work around this, output the contents of Objects into a file and then use that file in the linking step. This way, instead of passing in the large string that is Objects, only a file path is passed to the link command. See this updated makefile where a for loop is used to iterate Objects and echo each entry to a file.

OBJECTS := $(subst .cpp,.obj, $(SOURCES)) @for %%i in ($(OBJECTS)) do @echo %%i >> objectFiles.txt LINK @objectFiles.txt /out:$@ del objectFiles.txt

Note that it is not possible to simply do @echo $(OBJECTS) >> objectFiles.txt as this runs into the 8192 character limit.

 

Related pages