jam*_*o00 15 c++ header precompiled-headers visual-studio visual-c++
更新:
在我的头文件中包含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>
...
Run Code Online (Sandbox Code Playgroud)
和我的stdafx.cpp
#include "stdafx.h"
Run Code Online (Sandbox Code Playgroud)
在每个.h和.cpp文件中,我有以下内容:
#pragma once //if in a header file
#include "stdafx.h"
Run Code Online (Sandbox Code Playgroud)
对于发布和调试,我都有"创建预编译头(/ Yc)".它在调试模式下编译良好,但在发布模式下它保持报告
error LNK2005: ___@@_PchSym_@00@UfhvihUaszlaDUwlxfnvmghUnnlUhixUnnlPeDUnnlPeDUivovzhvUvmgrgbOlyq@ already defined in A.obj
Run Code Online (Sandbox Code Playgroud)
如果我同时切换到"使用预编译头",我会进入Debug和Release
fatal error C1854: cannot overwrite information formed during creation of the precompiled header in object file:
Run Code Online (Sandbox Code Playgroud)
有谁知道发生了什么?
180*_*ION 30
您只为stdafx.cpp添加"create precompiled header".然后为所有其他".cpp"文件"使用预编译头".最后,include "stdafx.h"
在每个".cpp"文件的开头(通常不在头文件中).