Select the product you need help with
- Internet Explorer
- Windows Phone
- More products
Troubleshooting for the Microsoft Visual C++ Compiler or the Visual C++ Linker
Article ID: 974229 - View products that this article applies to.
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.
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.
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.
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:
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:
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:
Before doing this, use the following command to switch off this feature if using the command line environment variable:
You can also use this process to verify the files involved in creating a library, when using LIB.EXE or LINK /LIB.
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.
(http://go.microsoft.com/fwlink/?LinkId=151500)for other considerations.
Article ID: 974229 - Last Review: January 24, 2013 - Revision: 2.0