c++ - 预编译 header 和 __AFXWIN_H__

标签 c++ visual-studio visual-c++

我创建了简单的 win32 控制台应用程序:

#include "stdafx.h"
#include <iostream>
#include "conio.h"
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    cout << "Hello World" << endl;

    int num;
    cin >> num;

    return 0;
}

它编译得很好。

然后我尝试添加库。我有 dll 库和 .h 文件。

我包含了 my.h 文件:

#include "stdafx.h"
#include "my.h"
#include <iostream>
#include "conio.h"

"my.h" 包含行:

#ifndef __AFXWIN_H__
    #error include 'stdafx.h' before including this file for PCH
#endif

编译后报错:

 include 'stdafx.h' before including this file for PCH

但我已经包含了“stdafx.h”。我已经测试了使用/不使用预编译 header 的两个选项 - 结果相同。问题出在哪里?

最佳答案

您的 my.h 使用 MFC(__AFXWIN_H__ 由 MFC header 定义)但您的控制台程序不是。您必须在您的程序中使用 MFC 或重写您的库以不使用 MFC。

关于c++ - 预编译 header 和 __AFXWIN_H__,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22147835/

相关文章:

c++ - 使用QDOMDocument获取第一级子节点

c++ - 当我尝试提交 mkbudget spoj 时得到 WA

c++ - 如果未选中任何项目,则禁用某些上下文菜单项

c++ - 可变长度数组何时合法?

c++ - 如何打印double变量中包含的正确位数?

.net - 如何诊断 Resharper 单元测试运行器 "Unable to load one or more of the requested types"错误

c# - 为什么此单元测试在 Visual Studio 2005 中通过但在 VS2008 中失败?

c# - TextTransform.exe 似乎只接受旧版本的 C#

c++ - 在 Visual Studio 中调整目录结构搞乱了#includes?

c++ - Windows 应用程序占用过多内存。有什么建议吗?