error C2065: 'AfxGetFileName' : undeclared identifier

来源:互联网 发布:poser人体造型软件 编辑:程序博客网 时间:2024/06/06 13:21

——————–Configuration: SCommTest - Win32 Release——————–
Compiling…
APPINIT.CPP
D:\VC++学习资料\vc6_win8\vc++6.0_win8\VC98\MFC\SRC\APPINIT.CPP(89) : error C2065: ‘AfxGetFileName’ : undeclared identifier
D:\VC++学习资料\vc6_win8\vc++6.0_win8\VC98\MFC\SRC\APPINIT.CPP(101) : error C2065: ‘AfxLoadString’ : undeclared identifier
D:\VC++学习资料\vc6_win8\vc++6.0_win8\VC98\MFC\SRC\APPINIT.CPP(138) : error C2373: ‘AfxGetFileName’ : redefinition; different type modifiers
执行 cl.exe 时出错.

解决报错问题:
头文件加上#include “stdAfx.h” 就可以正常运行了,特别注意要这两个头文件同时存在才能编译成功

include “stdafx.h”

include “stdAfx.h”

预编译头文件通过编译stdafx.cpp生成,以工程名命名,由于预编译的头文件的后缀是“pch”,所以编译结果文件是projectname.pch。

include “stdAfx.h”是预编译头文件

编译器通过一个头文件stdafx.h来使用预编译头文件。stdafx.h这个头文件名是可以在project的编译设置里指定的。编译器认为,所有在指令#include “stdafx.h”前的代码都是预编译的,它跳过#include “stdafx. h”指令,使用projectname.pch编译这条指令之后的所有代码。

因此,所有的MFC实现文件第一条语句都是:#include “stdafx.h”。在它前面的所有代码将被忽略,所以其他的头文件应该在这一行后面被包含。否则,你将会得到“No such file or directory”这样让你百思不得其解的错误提示。
stdafx.h中没有函数库,只是定义了一些环境参数,使得编译出来的程序能在32位的操作系统环境下运行。