今天用vc6遇到几个小问题,问题虽然小,但浪费了我不少时间,这几个问题可以说是vc6的bug,问题如下:
1.unexpected end of file while looking for precompiled header directive
原因不清楚,一般工程不会出现此问题,这次出现此问题主要是我用了于士其写的关于免装dxshow所写的类CameraDS所导致(解决此问题是一个非常痛苦的过程),解决方法是 工程->设置->所有配置->c/c++->预编译头文件->自动使用预补偿页眉
2.在Visual C++ 中以错误的顺序链接CRT 库和MFC 库时出现LNK2005 错误
上网搜到微软的解答,具体网址:http://support.microsoft.com/kb/148652/zh-cn
症状
当 C 运行时 (CRT) 库和 Microsoft 基础类 (MFC) 库的链接顺序有误时,可能会出现以下 LNK2005 错误之一:
nafxcwd.lib(afxmem.obj) :error LNK2005:
"void * __cdecl operator new(unsigned int)"(??2@YAPAXI@Z) already
defined in LIBCMTD.lib(new.obj)
nafxcwd.lib(afxmem.obj) :error LNK2005:
"void __cdecl operator delete(void *)"(??3@YAXPAX@Z) already defined
in LIBCMTD.lib(dbgnew.obj)
nafxcwd.lib(afxmem.obj) :error LNK2005:
"void * __cdecl operator new(unsigned int,int,char const *,int)"
(??2@YAPAXIHPBDH@Z) already defined in LIBCMTD.lib(dbgnew.obj)
mfcs40d.lib(dllmodul.obj):error LNK2005:_DllMain@12 already defined in
MSVCRTD.LIB (dllmain.obj)
mfcs42d.lib(dllmodul.obj):error LNK2005:_DllMain@12 already defined in
msvcrtd.lib(dllmain.obj)
原因
CRT 库对 new、delete 和 DllMain 函数使用弱外部链接。MFC 库也包含 new、delete 和 DllMain 函数。这些函数要求先链接 MFC 库,然后再链接 CRT 库。
解决方案
该问题有两种解决方法。第一种方法是强制链接器按照正确的顺序链接库。第二种方法是由您亲自查找导致问题的模块并纠正它。
注意:下列步骤基于 Visual C++ 6.0 进行。
解决方案一:强制链接器按照正确的顺序链接库
1.
在“项目”菜单上,单击“设置”。
2.
在“项目设置”对话框的“以下项目的设置”视图中,单击以选中出现链接错误的项目配置。
3.
在“链接”选项卡上,单击以选中“类别”组合框中的“输入”。
4.
在“忽略库”框中,插入库名(例如,Nafxcwd.lib;Libcmtd.lib)。
注意:等效的链接器命令行是:/NOD:<library name>。
5.
在“对象/库模块”框中,插入库名。必须确保这些库按顺序列出,而且是行中的前两个库(例如,Nafxcwd.lib 和 Libcmtd.lib)。
要在 Visual C++ .NET 中设置该选项,请阅读“设置 Visual C++ 项目属性”联机帮助主题。
3.error C2833: 'operator DEBUG_NEW' is not a recognized operator or type
也是上网找到答案的,这是vc6编译的bug,用2005则没此问题,原因及解决方法如下:
Symptom:
When compiling an application (in which a header file has just been changed) the Microsoft Visual C++ compiler generates the compiler error:
... /include/crtdbg.h (536) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type
followed by in excess of 20 errors.
Cause
Normally the compiler error C2833 means that the specified symbol is not recognised and this indicates a simple programming error.
This specific error, in ‘crtdbg.h’ involving ‘operator DEBUG_NEW
’, is a compiler bug. This bug has been observed in Visual Studio 5 and Visual Studio 6 (up to and including service pack 5).
Possible Remedies:
These remedies deal with the compiler bug only.
-
Try recompiling. This sometimes cures the problem.
-
If recompiling does not cure the problem then ‘clean’ the affected project and rebuild. This has always been observed to cure the problem.
-
Anders Musikka has contributed the following tip: It is not necessary to do a full clean of the project and rebuild. You can just delete the xxx.pch file in the debug/release directory and recompile the failed .cpp file(s).
Whilst it is in no way conclusive, this bug may be related to the project precompiler header settings. I have noticed that it only seems to affect projects where the precompiled headers is set to ‘automatic use of precompiled headers’.
写了一大堆,其实就是清除debug文件后重建。