gpt4 book ai didi

c++ - Visual C++ 预编译头错误

转载 作者:IT老高 更新时间:2023-10-28 22:23:30 25 4
gpt4 key购买 nike

更新:

在我的头文件中包含 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)”。它在 Debug模式下编译良好,但在 Release模式下它会不断报告

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:

有人知道怎么回事吗?

最佳答案

您只为 stdafx.cpp 放置了“创建预编译头”。然后对所有其他“.cpp”文件“使用预编译头文件”。最后,include "stdafx.h" 在每个“.cpp”文件的开头(通常不在头文件中。

关于c++ - Visual C++ 预编译头错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1397190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com