Troubleshooting for the Microsoft Visual C++ Compiler or the Visual C++ Linker

Article translations Article translations
Close Close
Article ID: 974229 - View products that this article applies to.
Expand all | Collapse all

RAPID PUBLISHING

RAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.

Action

When investigating 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 troubleshooting tips to help resolve your build problem or capture comprehensive information for Microsoft Support.

Resolution

Compiler Problems



For compiler problems, such as internal compiler errors (i.e. C1001), hangs, or crashes, it can be useful to capture the output of the C/C++ preprocessor in order to provide a simplified reproducible problem sample. In the Visual C++ IDE, this can be done by setting the "Generate Preprocessed File" property to "With Line Numbers (/P)" or "Without Line Numbers (/EP /P)". This property can be found under the project property pages under Configuration Properties, C/C++,Preprocessor settings.

This setting can be set at the project level from the Project, Properties menu in which case it will generate .i files for all source files in the project or it can be set for a single file by right-clicking the file in the solution explorer, selecting the Properties context menu to bring up the properties dialog for the single file.

The /P compiler switch directs CL.EXE to capture preprocessor output to a file. Adding /EP will suppress the addition of line number information to the resulting file. /P is usually sufficient, but /EP /P will generate a smaller output file. The generated preprocessor output file will have the same name as the source file being compiled but with a .i file extension, e.g. file1.cpp generates a file1.i preprocessor output file in the same directory. Note that the compilation will continue past the preprocessor phase when using this switch, i.e. no .OBJ file will be generated by the compiler and you may get a link error reflecting the fact that OBJ files cannot be found.

You can compile the preprocessor output file by itself outside of the context of a Visual Studio project. The .i 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. In other words, it is a self-contained module that should be able to reproduce a compilation problem without any dependencies on other files. The resulting file will often be very large and contain a large amount of white space.

Link Problems



For linker problems (LNKxxxx type errors), you can use the /LINKREPRO linker command line switch to generate a test case containing just linker inputs without any dependency on source files. /LINKREPRO uses the following syntax

/LINKREPRO:<path>

'<path>' is the full path to an empty folder on the local file system. This folder must already exist - the linker will not create it automatically and will generate an error if the folder does not exist.

This option is not directly exposed in the project system. To add it to a build, open the project Properties menu from the Project menu. In Configuration Properties, Linker, Command Line, in the Additional Options edit box, enter the /LINKREPRO:<path> switch (including the forward slash) and replacing path with the pre-existing local folder path. For example:

/LINKREPRO:C:\TEMP\LINKREPRO\

If there are other linker options already in this edit box, sperate them with commas.

Alternatively, you can use a LINK_REPRO environment variable. If the LINK_REPRO environment variable exists, the linker will read the output path from the environment variable and generate a linkrepro. The /LINKREPRO switch is not needed when using the LINK_REPRO environment variable. To use the LINK_REPRO environment variable:

1. Open up a Visual Studio Command Prompt. This is installed under the Start menu, In the Visual Studio folder under the Visual Studio Tools subfolder.

2. Create the LINK_REPRO environment variable pointing to an existing and empty directory, for example:

SET LINK_REPRO=C:\TEMP\LINKREPRO\

3. Run Visual Studio from the same command prompt so that it shares a copy of the environment you have just modified.

4. Open the project and do a Rebuild All of the project.

When LINK.EXE is invoked in the build, it will copy everything it needs to link your project into the linkrepro directory. 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 solution file.

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 generated by the linkrepro:
LINK @link.rsp

Before doing this, use the following command to switch off this feature if using the command line environment variable:
SET LINK_REPRO=

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

DISCLAIMER

MICROSOFT AND/OR ITS SUPPLIERS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY, RELIABILITY OR ACCURACY OF THE INFORMATION CONTAINED IN THE DOCUMENTS AND RELATED GRAPHICS PUBLISHED ON THIS WEBSITE (THE “MATERIALS”) FOR ANY PURPOSE. THE MATERIALS MAY INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS AND MAY BE REVISED AT ANY TIME WITHOUT NOTICE.

TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.
Note This is a "FAST PUBLISH" article created directly from within the Microsoft support organization. The information contained herein is provided as-is in response to emerging issues. As a result of the speed in making it available, the materials may include typographical errors and may be revised at any time without notice. See Terms of Use for other considerations.

Properties

Article ID: 974229 - Last Review: January 24, 2013 - Revision: 2.0
Applies to
  • Microsoft Visual C++ 2005 Express Edition
  • Microsoft Visual Studio 2005 Standard Edition
  • Microsoft Visual Studio 2005 Professional Edition
  • Microsoft Visual Studio 2005 Team Edition for Database Professionals
  • Microsoft Visual Studio 2005 Team Edition for Software Architects
  • Microsoft Visual Studio 2005 Team Edition for Software Developers
  • Microsoft Visual Studio 2005 Team Edition for Software Testers
  • Microsoft Visual C++ 2008 Express Edition
  • Microsoft Visual Studio 2008 Standard Edition
  • Microsoft Visual Studio 2008 Professional Edition
  • Microsoft Visual Studio Team System 2008 Database Edition
  • Microsoft Visual Studio Team System 2008 Architecture Edition
  • Microsoft Visual Studio Team System 2008 Development Edition
  • Microsoft Visual Studio Team System 2008 Test Edition
  • Microsoft Visual C++ 2010 Express
  • Microsoft Visual Studio 2010 Professional
  • Microsoft Visual Studio 2010 Ultimate
  • Microsoft Visual Studio Express 2012 for Windows 8
  • Microsoft Visual Studio Express 2012 for Windows Desktop
  • Microsoft Visual Studio Express 2012 for Windows Phone
  • Microsoft Visual Studio 2010 Premium
  • Microsoft Visual Studio Premium 2012
  • Microsoft Visual Studio Professional 2012
  • Microsoft Visual Studio Ultimate 2012
Keywords: 
kbrapidpub kbnomt KB974229

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com