суббота, 8 марта 2014 г.
Visual Studio 2010 решение проблемы с fatal error LNK1123
При работе с различными версиями Visual Studio и .Net Frameworks иногда возникают досадные неувязки. Далее о том, что делать, если линкер при сборке C++ проекта ругается следующим образом
LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt
Почему такое случается?
1)Вы запускаете VS 2010 после установки VS 2012.
2) Был установлен новый .Net Framework 4.5
3) Файлы .Net Framework 4 не в порядке (повреждены или удалены)
4) Файлы VS 2010 не в порядке.
Как решить проблему для одного проекта?
Чтобы ваш проект линковал в не инкрементальном режиме можно установить в опциях проекта Linker-> General->Incremental Linking значение NO. Это, конечно, имеет свои последствия, но зато обходит нашу текущую проблему.
сбой при преобразовании в COFF: файл недопустим или поврежден failure during conversion to COFF: file invalid or corrupt
Входные файлы должны иметь формат COFF. Input files must have the Common Object File Format (COFF) format. Если входной файл не имеет формат COFF, компоновщик автоматически пытается преобразовать 32-разрядные объекты OMF в формат COFF или запускает программу CVTRES.EXE для преобразования файлов ресурсов. If an input file is not COFF, the linker automatically tries to convert 32-bit OMF objects to COFF, or runs CVTRES.EXE to convert resource files. Это сообщение означает, что компоновщик не может преобразовать файл. This message indicates that the linker could not convert the file. Эта ошибка также может происходить при использовании несовместимой версии CVTRES.EXE из другой установки Visual Studio, пакета средств разработки программного обеспечения для Windows или платформы .NET Framework. This can also occur when using an incompatible version of CVTRES.EXE from another installation of Visual Studio, the Windows Development Kit, or .NET Framework.
Если используется более ранняя версия Visual Studio, автоматическое преобразование может не поддерживаться. If you are running an earlier version of Visual Studio, automatic conversion may not be supported.
Устранение проблемы To fix the problem
Примените все обновления и пакеты обновления для используемой версии Visual Studio. Apply all service packs and updates for your version of Visual Studio. Это особенно важно для Visual Studio 2010. This is particularly important for Visual Studio 2010.
Попробуйте выполнить сборку с отключенной инкрементной компоновкой. Try building with incremental linking disabled. В строке меню выберите Проект, Свойства. On the menu bar, choose Project, Properties. В диалоговом окне страницы свойств разверните узел Свойства конфигурации, Компоновщик. In the Property Pages dialog box, expand Configuration Properties, Linker. Измените значение параметра Включить инкрементную компоновку в нет. Change the value of Enable Incremental Linking to No.
Проверьте, соответствует ли версия CVTRES.EXE, указанная первой в переменной среды PATH, версии средств сборки или используемого проектом набора инструментов платформы,. Verify that the version of CVTRES.EXE found first in your PATH environment variable matches the version of the build tools, or the version of the Platform Toolset, used by your project.
Попробуйте отключить параметр «Внедренный манифест». Try turning off the Embed Manifest option. В строке меню выберите Проект, Свойства. On the menu bar, choose Project, Properties. В диалоговом окне страницы свойств разверните узел Свойства конфигурации, инструмент манифеста, Ввод и вывод. In the Property Pages dialog box, expand Configuration Properties, Manifest Tool, Input and Output. Измените значение параметра внедрить манифест на нет. Change the value of Embed Manifest to No.
Убедитесь в том, что тип файла является допустимым. Make sure that the file type is valid. Например, убедитесь в том, что объект OMF 32-разрядный, а не 16-разрядный. For example, make sure that an OMF object is 32-bit and not 16-bit. Дополнительные сведения см. в разделе . OBJ-файлы в качестве входных и PE-файлов компоновщика. For more information, see .Obj Files as Linker Input and PE Format.
Убедитесь в том, что файл не поврежден. Make sure that the file is not corrupt. Заново выполните сборку, если нужно. Rebuild it, if necessary.
I’ve installed Visual Studio 2012 Release Preview, and it appears to be fine, but now when I try to use Visual Studio 2010 to compile C++ projects, I get the following error message:
LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt
I’m not 100% sure of this, but it seems to be related to projects that have .rc (resource) files in them.
I’ve tried repairing Visual Studio 2010 from Add/Remove programs and rebooting, but this has no effect.
I also get the same error if I use Visual Studio 2012 RC to compile the C++ projects when set to use the Visual Studio 2010 toolset. Upgrading to the Visual Studio 2011 toolset fixes the problem (but of course I don’t want to do this for production code).
Update: I’ve uninstalled Visual Studio 2012, rebooted, and the problem still persists! Help!

26 Answers 26
This MSDN thread explains how to fix it.
Either disable incremental linking, by going to
or install VS2010 SP1.
Edits (@CraigRinger): Note that installing VS 2010 SP1 will remove the 64-bit compilers. You need to install the VS 2010 SP1 compiler pack to get them back.
This affects Microsoft Windows SDK 7.1 for Windows 7 and .NET 4.0 as well as Visual Studio 2010.

If disabling incremental linking doesn’t work for you, and turning off «Embed Manifest» doesn’t work either, then search your path for multiple versions of CVTRES.exe.
By debugging with the /VERBOSE linker option I found the linker was writing that error message when it tried to invoke cvtres and it failed.
It turned out that I had two versions of this utility in my path. One at C:Program Files (x86)Microsoft Visual Studio 10.0VCBINcvtres.exe and one at C:WindowsMicrosoft.NETFrameworkv4.0.30319cvtres.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.