FIX: LNK1170 Building Project's Makefile from Command Line (156190)



The information in this article applies to:

  • The Program Maintenance Utility (NMAKE.EXE), when used with:
    • Microsoft Visual C++, 32-bit Editions 4.0
    • Microsoft Visual C++, 32-bit Editions 4.1
    • Microsoft Visual C++, 32-bit Enterprise Edition 4.2
    • Microsoft Visual C++, 32-bit Professional Edition 4.2

This article was previously published under Q156190

SYMPTOMS

When using the NMAKE utility to build a large project created in Visual C++, you may encounter the following error:
fatal error LNK1170: line in command file contains 16383 or more characters

CAUSE

Visual C++ generates the project makefile such that all of the object modules are placed on one line in an inline response file for LINK. LINK cannot accept more than 16383 characters on one line.

WORKAROUND

There are two workarounds:

Workaround 1: A New Makefile

Copy the project makefile and edit the copy. The object modules are listed in the LINK32_OBJS macro. To work around the problem, use macro substitution to insert newline charaters after each object module so that each object module is specified on a separate line. You need to use the following macro substitution in your project makefile:
   $(LINK32_OBJS:"  "="^
   ")
					
For example, a typical link line in a makefile looks similar to the following:
   "$(OUTDIR)\anapp.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
       $(LINK32) @<<
    $(LINK32_FLAGS) $(LINK32_OBJS)
   <<
				
Change the third line of the above sample to the following:
   "$(OUTDIR)\anapp.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
       $(LINK32) @<<
    $(LINK32_FLAGS) $(LINK32_OBJS:"  "="^
   ")
   <<
					
NOTE: Two white spaces between the initial set of quotes.

You need to use the workaround for both the debug build and the release build of your project. If you have any other project configurations, you need to apply the workaround to those as well.

Then use NMAKE on the new makefile to build your project.

Workaround 2: Static Libraries

Break up your project into a main top-level project and several static libraries as sub-projects. Static libraries are simply a collection of object modules. You can organize your project into several such collections, but you must have at least one module in your top-level project--the one containing the entry point of your program.

STATUS

Microsoft has confirmed this to be an issue in the Microsoft products listed at the beginning of this article. This bug was corrected in Visual C++ version 5.0.

REFERENCES

Visual C++ version 4.2, Visual C++ Books Online; click Visual C++ Books, User's Guides, Visual C++ User's Guide, Working with Projects, Using Projects, and then click the "Inserting and Deleting Projects" topic.

Visual C++ version 4.2, Visual C++ Books Online; click Visual C++ Books, User's Guides, Visual C++ User's Guide, NMAKE Reference, and then the "NMAKE Reference" topic.

Visual C++ version 4.2, Visual C++ Books Online; click Visual C++ Books, User's Guides, Visual C++ User's Guide, Working with Projects, Managing Project Workspaces, Creating a Project Workspace, and the "Project Types" topic.

Visual C++ version 4.2, Visual C++ Books Online; click Visual C++ Books, User's Guides, Visual C++ User's Guide, NMAKE Reference, Macros and NMAKE, Using an NMAKE Macro, and then click the "Macro Substitution" topic.

Modification Type:MajorLast Reviewed:12/2/2003
Keywords:kbbug kbfix kbVC500fix KB156190