Microsoft KB Archive/156190

= FIX: LNK1170 Building Project's Makefile from Command Line =

Article ID: 156190

Article Last Modified on 12/2/2003

-

APPLIES TO

 Microsoft Program Maintenance Utility 1.4, when used with:  Microsoft Visual C++ 4.0 Standard Edition

 Microsoft Visual C++ 4.1 Subscription

 Microsoft Visual C++ 4.2 Enterprise Edition

 Microsoft Visual C++ 4.2 Professional Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q156190

<div class="symptoms_section">

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

<div class="cause_section">

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.

<div class="workaround_section">

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.

<div class="status_section">

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.

<div class="references_section">