更新:
在我的头文件中包含 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
#include "stdafx.h"
在每个 .h 和 .cpp 文件中,我都有以下内容:
#pragma once //if in a header file
#include "stdafx.h"
对于发布和调试,我都有“创建预编译头文件 (/Yc)”。它在调试模式下编译得很好,但在发布模式下它会不断报告
error LNK2005: ___@@_PchSym_@00@UfhvihUaszlaDUwlxfnvmghUnnlUhixUnnlPeDUnnlPeDUivovzhvUvmgrgbOlyq@ already defined in A.obj
如果我同时切换到“使用预编译头”,我会同时进入调试和发布
fatal error C1854: cannot overwrite information formed during creation of the precompiled header in object file:
有谁知道发生了什么?