fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
原创作品,允许转载,转载时请务必以超链接形式标明文章原始出处、作者信息和本声明。否则将追究法律责任。http://blog.csdn.net/taotaoyouarebaby/article/details/8886563
说明:
该问题的解决方案我不可能一个一个的去验证。那些方法都是我从网上整理而来,因此你在使用时要小心为上,做好备份。
之前装了VS2012,将其卸载之后装回到了VS2010。在卸载VS2012时被中断了,导致了一些文件残留。在使用VS2010新建VC控制台项目后都会出现该错误。
.NET Framework 4.5 is an in-place update that replaces .NET Framework 4 (rather than a side-by-side installation). Our goal is for .NET 4.5 to be fully backward compatible with applications built for .NET 4 (.NET 3.5 and .NET 4.5 will be side-by-side). We’ll talk about the compatibility story for .NET 3.5 in a later post. One of the first things you’ll notice about .NET 4.5 is the version number (4.0.30319) is the same as .NET 4; this is the practice used by other in-place updates.
参考:
http://blogs.msdn.com/b/dotnet/archive/2011/09/26/compatibility-of-net-framework-4-5.aspx
...the x86 version of cvtres.exe had changed.
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\cvtres.exe
Wrong version: 03/18/2010 01:16 PM 31,048 cvtres.exe
Correct version: 02/21/2011 06:03 PM 31,056 cvtres.exe
The wrong version has a dependancy on msvcr100_clr0400.dll
The correct version has a dependancy on msvcr100.dll
PS:
cvtres.exe
功能:Microsoft® Resource File To COFF Object Conversion Utility
Common Object File Format (COFF)
a specification of a format for executable, object code, and shared library computer files used onUnix systems. It was introduced in Unix System V, replaced the previously used a.out format, and formed the basis for extended specifications such as XCOFF and ECOFF, before being largely replaced by ELF, introduced with SVR4. COFF and its variants continue to be used on some Unix-like systems, on Microsoft Windows, in EFIenvironments and in some embedded development systems.
While extended versions of COFF continue to be used for some Unix-like platforms, primarily in embedded systems, perhaps the most widespread use of the COFF format today is in Microsoft's Portable Executable (PE) format. Developed for Windows NT, the PE format (sometimes written as PE/COFF) uses a COFF header for object files, and as a component of the PE header for executable files.
参考:
http://stackoverflow.com/questions/10888391/link-fatal-error-lnk1123-failure-during-conversion-to-coff-file-invalid-or-c
因为是cvtres.exe版本错误导致的结果,所以凡是能使VS链接器找到正确的cvtres.exe版本的方法都可以解决该问题。或者使VS链接器不生成COFF的方法都可以。
以下解决方法按简易程度排列:
当前系统中存在两个cvtres.exe文件,版本不同。让VS2010使用.NET 4.5的cvtres.exe程序。
具体步骤:
重命名或删除:C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\cvtres.exe
这样C:\Windows\Microsoft.NET\Framework\v4.0.30319 (.NET 4.5)中的cvtres.exe文件就可以被VS2010使用。
参考:
http://social.msdn.microsoft.com/Forums/en-US/vssetup/thread/d10adba0-e082-494a-bb16-2bfc039faa80 by RatnaAyu
更换平台工具:
Project Properties -> Configuration Properties -> General -> Platform Toolset -> "Visual Studio 2012 (v110)" |
该方法是用于VS2012与VS2010共存的情况下使用的。
英文版:
Project Properties -> Configuration Properties -> Linker (General) -> Enable Incremental Linking -> "No (/INCREMENTAL:NO)" |
中文版:
项目属性 -> 配置属性 -> 链接器 -> 常规 -> 启用增量链接 -> "No (/INCREMENTAL:NO)" |
方法简单,但是必须对每一个新建的项目都进行同样的设置。
安装:VS2010 SP1. 该版本应该是能使用.NET 4.5的,并配有正确的cvtres.exe版本。
注意:安装VS 2010 SP1 时会移除64-bit 编译器. 通过安装 VS 2010 SP1 compiler pack 能够重新获得。
卸载.NET 4.5,重装.NET 4.0
要想让VS2012与VS2010共存,只需要用VS2012的cvtres.exe替换VS2010的cvtres.exe即可。