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

This article provides resolutions for troubleshooting for Visual C++ Compiler or Visual C++ Linker.

Applies to:   Microsoft Visual C++ 2010 Express, Visual Studio
Original KB number:   974229


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.


  • Compiler Problems

    For compiler problems, such as internal compiler errors (that is, 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 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, for example, file1.cpp generates a file1.i preprocessor output file in the same directory.


    The compilation will continue past the preprocessor phase when using this switch, that is, 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 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:


    '<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, separate 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 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.


Rapid Publishing Disclaimer

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.


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.