Troubleshooting for the Microsoft Visual C++ Compiler or the Visual C++ Linker (134650)



The information in this article applies to:

  • Microsoft Visual C++ 1.0
  • Microsoft Visual C++ 2.0
  • Microsoft Visual C++ 2.1
  • Microsoft Visual C++ 2.2
  • Microsoft Visual C++ 4.0
  • Microsoft Visual C++ 4.1
  • Microsoft Visual C++, 32-bit Enterprise Edition 5.0
  • Microsoft Visual C++, 32-bit Enterprise Edition 6.0
  • Microsoft Visual C++, 32-bit Professional Edition 5.0
  • Microsoft Visual C++, 32-bit Professional Edition 6.0
  • Microsoft Visual C++, 32-bit Learning Edition 6.0

This article was previously published under Q134650

SUMMARY

When you investigate a possible problem with the Microsoft Visual C++ compiler or linker, it is important to obtain as much information as possible about the build process and the options being used. This article discusses some trouble-shooting tips to help you resolve your build problem.

MORE INFORMATION

Compiler Problems

For compiler problems, such as internal compiler errors (for example, C1001), hangs, or crashes, use the /P switch to obtain additional compiler information. The /P compiler switch directs CL.EXE to send preprocessor output to a file. The preprocessor output file (with an extension of .i) has the same name as the file being compiled and is created in the same directory. Note that the build will not continue past the preprocessor phase when using this switch.

You can compile the preprocessor output file by itself outside of the context of a project. The file contains all of the header file code, macro replacement, and preprocessed compiler directive information needed for the compilation of that particular .C or .CPP source file. The resulting file will often be long and contain a large amount of white space.

Alternatively, you can use the /EP and /E compiler switches, which direct CL.EXE to send preprocessor output to the standard output device.

Link Problems

For linker problems (LNKxxxx type errors), you can use the LINK_REPRO environment variable to reproduce the problem:
  1. Open up an MS-DOS session.
  2. Set LINK_REPRO to point to an existing and empty directory, for example:

    SET LINK_REPRO=C:\TESTPROB

  3. Run the linker in the same MS-DOS session where the variable was set.
  4. Run the VCVARS32.BAT file from the Visual C++ BIN directory to set the compiler environment variables.
  5. Change to your project directory, and run NMAKE to rebuild your project, using this command:

NMAKE /a /f yourproj.mak

The /a option directs NMAKE to perform a complete rebuild of the project.

When LINK.EXE is invoked, it will copy everything it needs to link your project into the directory specified by the LINK_REPRO environment variable. Among the files copied will be your object files (*.OBJ), required library files (*.LIB), including Microsoft libraries, and a linker response file (LINK.RSP), so that LINK is no longer dependent on your project makefile.

This feature is also available from the IDE if it has been run from an environment where the LINK_REPRO variable has been set.

To confirm that you have all the necessary files to reproduce the link problem, you can run LINK in the directory specified by the LINK_REPRO environment variable, using the linker response file:

LINK @link.rsp

Use the following command to switch off this feature:

SET LINK_REPRO=

You can also use the LINK_REPRO environment variable to verify the files involved in creating a library, when using LIB.EXE or LINK /LIB.

Modification Type:MajorLast Reviewed:4/28/2005
Keywords:kbtshoot kbinfo kbArtTypeINF kbCompiler kbCPPonly KB134650 kbAudDeveloper