visual-studio 错误 C1854:无法覆盖在目标文件中创建预编译头期间形成的信息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/944429/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:36:17  来源:igfitidea点击:

error C1854: cannot overwrite information formed during creation of the precompiled header in object file

c++visual-studioprecompiled-headersdllexport

提问by ralphtheninja

foo.cpp(33918) : fatal error C1854: cannot overwrite information formed 
during creation of the precompiled header in object file: 'c:\somepath\foo.obj'

Consulting MSDN about this gives me the following information:

就此咨询 MSDN 给了我以下信息:

You specified the /Yu (use precompiled header) option after specifying the /Yc (create precompiled header) option for the same file. Certain declarations (such as declarations including __declspec dllexport) make this invalid.

在为同一文件指定 /Yc(创建预编译头)选项后指定了 /Yu(使用预编译头)选项。某些声明(例如包括 __declspec dllexport 的声明)使其无效。

We are using dllexport and precompiled headers in this case. Have anyone encountered this before and know of any workaround? Any input to shed some light on this problem is greatly appreciated.

在这种情况下,我们使用 dllexport 和预编译头。有没有人遇到过这种情况并知道任何解决方法?非常感谢任何可以阐明这个问题的意见。

Thanks

谢谢

回答by cspirz

I think you can find the answer here: http://social.msdn.microsoft.com/forums/en-US/vclanguage/thread/b3aa10fa-141b-4a03-934c-7e463f92b2a5/

我想你可以在这里找到答案:http: //social.msdn.microsoft.com/forums/en-US/vclanguage/thread/b3aa10fa-141b-4a03-934c-7e463f92b2a5/

Basically, you need to set the stdafx.cpp file to "Create Precompiled Headers" and all the other .cpp files to "Use Precompiled Headers"

基本上,您需要将 stdafx.cpp 文件设置为“创建预编译头文件”,并将所有其他 .cpp 文件设置为“使用预编译头文件”

回答by Tony

I had this problem too.

我也有这个问题。

Make sure the precompiler header output file is set to the correct location. Mine was actually outputted to the right location, but there were problems reading it just because the path had a little artifact inside.

确保预编译器头文件输出文件设置到正确的位置。我的实际上输出到了正确的位置,但是读取它只是因为路径中有一个小工件而出现问题。

回答by user3699614

My solution was to carefully recheck all the precompiled header settings in not just the .exe project but all the dll projects also and recreate all the headers. After that the error was gone in the .exe compilation.

我的解决方案是仔细重新检查 .exe 项目和所有 dll 项目中的所有预编译头设置,并重新创建所有头。之后,错误在 .exe 编译中消失了。