Visual C ++预编译头文件错误 [英] Visual C++ Precompiled Headers errors

查看:182
本文介绍了Visual C ++预编译头文件错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b 在我的头文件中包含stdafx.h的效果如何?






我从Linux / Eclipse CDT中的C ++项目开始,并将其导入Visual C ++ / Windows。

在Visual C ++中,我开始使用预编译头文件来加速编译并定义stdafx.cpp和stdafx.h。



这是我的stdafx.h

  #pragma once 

#include< string>
#include< vector>
#include< map>
...

和我的stdafx.cpp

  #includestdafx.h

在每个.h和.cpp文件中,我都有以下内容:

  #pragma once // if if in a header file 
#includestdafx.h

对于发布和调试,我都有Create Precompiled标题(/ Yc)。它以调试方式编译罚款,但在释放模式它使报告

 错误LNK2005:___ @@ _ PchSym_ @ 00 @ UfhvihUaszlaDUwlxfnvmghUnnlUhixUnnlPeDUnnlPeDUivovzhvUvmgrgbOlyq @已经在A.obj中定义

如果我同时切换到使用预编译头文件调试和发布

 致命错误C1854:无法覆盖在对象文件中创建预编译头期间形成的信息:

有谁知道发生了什么事? / div>

只为stdafx.cpp添加创建预编译头文件。然后为所有其他.cpp文件使用预编译头文件。最后,在每个.cpp文件的开始部分包含stdafx.h(通常不在头文件中)。


Update:

What are the effects of including stdafx.h in my header files?


I started on a C++ project in Linux/Eclipse CDT and imported it into Visual C++/Windows.

In Visual C++, I started using precompiled headers to speed up compilation and defined stdafx.cpp and stdafx.h.

Here's my stdafx.h

#pragma once

#include <string>
#include <vector>
#include <map>
...

and my stdafx.cpp

#include "stdafx.h"

In every .h and .cpp file, I have the following:

#pragma once //if in a header file
#include "stdafx.h"

For both release and debug, I have "Create Precompiled Header (/Yc)". It compiled fine in debug mode, but in release mode it keeps reporting

error LNK2005: ___@@_PchSym_@00@UfhvihUaszlaDUwlxfnvmghUnnlUhixUnnlPeDUnnlPeDUivovzhvUvmgrgbOlyq@ already defined in A.obj

If I switch both to "Use precompiled header", I get in both Debug and Release

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

Does anyone know what's going on?

解决方案

You put "create precompiled header" only for stdafx.cpp. Then "use precompiled header" for all of the other ".cpp" files. Finally, have include "stdafx.h" at the start of each ".cpp" file (not usually in the header files.

这篇关于Visual C ++预编译头文件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆