我创建了简单的 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/