C++ 错误 C1047:使用比其他对象更旧的编译器创建的对象文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/837073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error C1047: Object file created with an older compiler than other objects
提问by Jared
I have a project that I'm building in C++ in Release mode in Visual Studio 2008 SP1 on Windows 7 and when I build it I keep getting:
我有一个项目,我正在 Windows 7 上的 Visual Studio 2008 SP1 中以 C++ 发布模式构建,当我构建它时,我不断得到:
fatal error C1047: The object or library file '.\Release\foobar.obj' was created with an older compiler than other objects; rebuild old objects and libraries.
致命错误 C1047:对象或库文件“.\Release\foobar.obj”是用比其他对象旧的编译器创建的;重建旧的对象和库。
The error occurs while linking.
链接时发生错误。
I've tried deleting the specific object file and rebuilding but that doesn't fix it. I've also tried blowing away the whole release build folder and rebuilding but that also didn't fix it. Any ideas?
我试过删除特定的对象文件并重建,但这并不能解决它。我也试过吹掉整个发布构建文件夹并重建,但这也没有解决它。有任何想法吗?
采纳答案by Tobiesque
I would suggest reinstalling VS 2008 SP1. Have you installed a different VS (e.g. VS Express) in the meantime? This is known to cause interference with an existing VS installation.
我建议重新安装 VS 2008 SP1。在此期间您是否安装了不同的 VS(例如 VS Express)?众所周知,这会干扰现有的 VS 安装。
You could try checking the compiler and linker versions by running cl.exe
and link.exe
from the Visual Studio command prompt.
您可以尝试通过从 Visual Studio 命令提示符运行cl.exe
和检查编译器和链接器版本link.exe
。
回答by Oliver Zendel
I had this problem but my solution differs:
我有这个问题,但我的解决方案不同:
For me the culprit was that an included external library was compiled with
对我来说,罪魁祸首是包含的外部库是用
/GL (=Enable link-time code generation under
C/C++/ Optimization / Whole Program Optimization)
using an older visual studio (2005). I rebuild said library in 2005 without /GL and the linker error disappeared in 2008. As MSDN states it has to do with the /LTCG setting, this is set automatically by the /GL flag: http://msdn.microsoft.com/en-us/library/ms173554%28v=vs.80%29.aspx
使用较旧的视觉工作室(2005)。我在 2005 年没有 /GL 的情况下重建了上述库,并且链接器错误在 2008 年消失了。正如 MSDN 所说,它与 /LTCG 设置有关,这是由 /GL 标志自动设置的:http: //msdn.microsoft.com/ en-us/library/ms173554%28v=vs.80%29.aspx
回答by Gank
Two ways:
两种方式:
1.Update to Sp1 to build the lib
1.更新到Sp1以构建lib
2.Please check your build to make sure that Whole Program Optimization is disabled. For a static lib project, go to the property page and change “Configuration Properties->C/C++->Optimization->Whole Program Optimization” to “No”.
2.请检查您的构建以确保禁用了整个程序优化。对于静态lib项目,进入属性页面,将“Configuration Properties->C/C++->Optimization->Whole Program Optimization”改为“No”。
回答by Pierre
I was able to fix this problem in VS 2015 with the following steps.
我能够通过以下步骤在 VS 2015 中解决这个问题。
[1] (Not sure this was necessary) Turn off /GL in all components
[1](不确定是否有必要)在所有组件中关闭 /GL
C/C++ > Optimization > Whole program Optimization > No
C/C++ > 优化 > 整个程序优化 > 否
In the .VCXPROJ files it's:
在 .VCXPROJ 文件中,它是:
<WholeProgramOptimization>false</WholeProgramOptimization>
Turn off /LTCG
关闭/LTCG
Librarian > General > Link Time Code Generation
图书馆员 > 常规 > 链接时间代码生成
<LinkTimeCodeGeneration>false</LinkTimeCodeGeneration>
[2] More important step, make sure all components are drawing from the same directories. My main EXE was using:
[2] 更重要的一步,确保所有组件都从相同的目录中绘制。我的主要 EXE 正在使用:
Release Include
$(WindowsSdkDir)include\um;$(WindowsSdkDir)include\shared;$(UniversalCRT_IncludePath);$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSdkDir)include;$(FrameworkSDKDir)\include
Release Library
$(VC_LibraryPath_x86);$(WindowsSdk_71A_LibraryPath_x86);
The .lib was using different directories (wrong):
.lib 使用了不同的目录(错误):
Release Include
$(VC_IncludePath);$(WindowsSDK_IncludePath);
Release Library
$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86
I changed the .lib directories to be the same as the .exe, and the compilation error disappeared.
我把.lib目录改成和.exe一样,编译错误就消失了。
回答by mark
Anyone finding this thread looking for answers... I ran into this as well, but it wasn't a SP1 problem or a rebuild problem or a PCH problem... it ended up being a library that was built with a more recent version of VS trying to link into a project on the older VS. While that sounds obvious, the odd part was VS2008 was reporting that an object that it compiledwas the cause of the problem which sent me on a wild goose chase...
任何找到此线程的人都在寻找答案......我也遇到了这个问题,但这不是 SP1 问题、重建问题或 PCH 问题......它最终成为一个用更新版本构建的库VS 试图链接到旧 VS 上的项目。虽然这听起来很明显,但奇怪的是 VS2008 报告说它编译的一个对象是问题的原因,这让我大吃一惊......
回答by cheburashka
It could also be that the offending library was built with a different "Platform Toolset" setting (in Project Properties->General).
也可能是违规库是使用不同的“平台工具集”设置(在项目属性->常规中)构建的。
回答by Eric
I had the same problem too, and my visual Studio About box reported I had SP1 installed. Apparently that was not entirely true. Investigation on my specific occurance to this problem reveiled the resource compiler seemed to be the culprid. It happened to be an older version, that caused the mentioned error message. My installed hotfixes (Windows update) did not solve that problem. Maybe I missed a crucial one.....
我也有同样的问题,我的 Visual Studio About 框报告我安装了 SP1。显然这并不完全正确。对我对这个问题的具体发生的调查揭示了资源编译器似乎是罪魁祸首。它碰巧是一个旧版本,导致了上述错误消息。我安装的修补程序(Windows 更新)没有解决这个问题。也许我错过了一个关键的.....
Hopefully we once experience the day developers will actually communicate back the real problem in their generated error messages. :-) 'an older version of a compiler....' come on guys, you can do better than that ;-)
希望我们曾经经历过开发人员会在他们生成的错误消息中实际传达真正问题的那一天。:-) '旧版本的编译器......' 伙计们,你可以做得更好;-)
Anyways, here is the downloadlink to the latest SP1 for VS2008 i've used to solve this problem.
不管怎样,这里是我用来解决这个问题的 VS2008 的最新 SP1 的下载链接。
Happy coding.
快乐编码。
回答by David
I try everything here... and my mistach become of a bad reference and duplicate GUID (between 2010 and 2015 project... the hell of copy/past project)
我在这里尝试了一切......我的错误变成了一个糟糕的参考和重复的 GUID(在 2010 和 2015 之间的项目......复制/过去项目的地狱)
During project migration from VS2008 to 2010 and 2015. We keep all project version XXX.vxproj (for VS2010) and XXX_2015.vxproj (for VS2015).
在从 VS2008 到 2010 和 2015 的项目迁移期间。我们保留所有项目版本 XXX.vxproj(对于 VS2010)和 XXX_2015.vxproj(对于 VS2015)。
And in one of them in 2015 solution we got a reference to 2010 project !
在其中一个 2015 年的解决方案中,我们得到了 2010 年项目的参考!
So check REFERENCE... and never duplicate GUID.
所以检查 REFERENCE... 并且永远不要重复 GUID。
回答by Anand
With reference to MSDN, this error
The object or library file 'file' was created with an older compiler than other objects; rebuild old objects and librariesis caused when object files or libraries built with /LTCG are linked together, but where those object files or libraries are built with different versions of the Visual C++ toolset.
This can happen if you begin using a new version of the compiler but do not do a clean rebuild of existing object files or libraries.
To resolve, rebuild all object files or libraries.
参考MSDN,这个错误
The object or library file 'file' was created with a old compiler than other objects; 当使用 /LTCG 构建的对象文件或库链接在一起时,会导致重建旧对象和库,但这些对象文件或库是使用不同版本的 Visual C++ 工具集构建的。
如果您开始使用新版本的编译器,但没有彻底重建现有的目标文件或库,就会发生这种情况。
要解决此问题,请重建所有目标文件或库。
回答by learnvst
I had the same problem, but a straight up reinstall did not fix it. I was using the version I found here
我遇到了同样的问题,但直接重新安装并没有解决它。我正在使用我在这里找到的版本
https://www.dreamspark.com/Products/Product.aspx?ProductId=9
https://www.dreamspark.com/Products/Product.aspx?ProductId=9
However, after trawling forums I found that installing VS2008 SP1 Express eliminates this problem. . . .
但是,在搜索论坛后我发现安装 VS2008 SP1 Express 可以消除这个问题。. . .
You have to be careful which place you download VS2008 from as different versions of the same Express product are available for download.
您必须小心从哪个位置下载 VS2008,因为可以下载同一 Express 产品的不同版本。