解决错误:fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt

排错

使用VS2010,CMake2.8.12,编译OSG3.2,刚开始configure就出现了错误,弹出框“Error in configuration process,project files may be invalid”。查找日志的时候发现了这个错误:

cl.exe is not able to compile a simple test program.
找了半天,几个解决方案都不能解决问题,只好继续寻找。在日志中还发现了另外一个错误:

LINK : fatal error LNK1123: failure during conversion to COFF: file

这个错误对于经常写c++的人来说很熟悉,于是查找这个错误。网上有几个通用的解决方法:

disable incremental linking

Project Properties -> Configuration Properties -> Linker (General) -> Enable Incremental Linking -> "No (/INCREMENTAL:NO)"
turning off "Embed Manifest"

这是用在vs解决方案中的工程设置里面的。但是我现在用的是CMake,是怎么回事呢?继续寻找。。。终于,在Stackoverflow上面找到了答案:

It turned out that I had two versions of this utility in my path. 
One at C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\cvtres.exe 
and one at C:\Windows\Microsoft.NET\Framework\v4.0.30319\cvtres.exe. 
After VS2012 install, the VS2010 version of cvtres.exe will no longer work. 
If that's the first one in your path, and the linker decides it needs to convert a .res 
file to COFF object format, the link will fail with LNK1123.

(Really annoying that the error message has nothing to do with the actual problem, 
but that's not unusual for a Microsoft product.)
Just delete/rename the older version of the utility, 
or re-arrange your PATH variable, so that the version that works comes first.

也就是说,系统中有2个cvtres.exe,分别位于 C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\cvtres.exe和C:\Windows\Microsoft.NET\Framework\v4.0.30319\cvtres.exe。如果使用第一个路径下面的程序就会有问题(不知道具体原因,难道是vs2010的bug?),如果使用第二个路径下面的就没有问题了。所以,最简单的解决方法就是,删除或者重命名一下第一个路径下面的cvtres,让CMake直接使用第二个路径下面的cvtres就可以了。

参考

http://stackoverflow.com/questions/10888391/error-link-fatal-error-lnk1123-failure-during-conversion-to-coff-file-inval

http://blog.csdn.net/junjiehe/article/details/16888197

你可能感兴趣的:(解决错误:fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt)