标头正确,但找不到标识符

时间:2010-03-26 20:51:23

标签: c++ c visual-studio-2008

我有两个项目(x64)。

A 即可。用C编写(wxWidgets)---编辑:用C ++编写!

即可。用C ++编写

A 编译正常,但 B (使用 A 的功能)在我尝试编译时会出现几个错误。

我建议所有错误的原因是相同的,所以我只提到第一个。 它说:

strlen: identifier not found

在提供错误消息的文件(wxcrtbase.h)中,包含以下标题:

#include <stdio.h>
#include <string.h>`

B 中的文件包含来自 A 的以下标题:

#include "wx/wx.h"
#include "wx/dcbuffer.h" 
#include "wx/spinctrl.h"

所以,目前,我不知道从哪里开始搜索错误的原因。可能是我有C和C ++文件?也许我为x64编译了?

感谢您的帮助!

编辑:更多信息
wxcrtbase.h中围绕产生第一条错误消息的行是:

#ifdef __cplusplus  
inline size_t wxStrlen(const char *s) { return s ? wxCRT_StrlenA(s) : 0; }  
inline size_t wxStrlen(const wchar_t *s) { return s ? wcslen(s) : 0; }  

wxcrtbase.h包含的顺序是

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <wctype.h>
#include <time.h>
#include <io.h>

/ showIncludes列出以下内容(我在前两条错误消息后停止列表):

1>Compiling...
1>widget.cpp
1>Note: including file: m:\visual studio 2008\projects\general\rama\src\widget.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include \string
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\ostream
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\ios
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xlocnum
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\climits
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\yvals.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\sal.h
1>Note: including file: c:\program files (x86)\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtassem.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\vadefs.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\use_ansi.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\limits.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\cstdio
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\stdio.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\swprintf.inl
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\cstdlib
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\stdlib.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\streambuf
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xiosbase
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xlocale
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\cstring
1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx\string.h
1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/defs.h
1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/platform.h
1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\setupp.h
1>Note: including file: m:\visual studio 2008\projects\general\wxwidgets-2.9.0\include\wx/version.h
1>Note: including file: m:\visual studio 2008\projects\general\wxwidgets-2.9.0\include\wx/cpp.h
1>Note: including file: m:\visual studio 2008\projects\general\wxwidgets-2.9.0\include\wx/cpp.h
1>Note: including file: M:/Visual Studio 2008/Projects/general/wxWidgets-2.9.0/lib/vc_lib/mswud/wx/setup.h
1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/msw/libraries.h
1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/chkconf.h
1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/msw/chkconf.h
1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/version.h
1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/dlimpexp.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\stddef.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/debug.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\assert.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file:  M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/chartype.h
1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/platform.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\tchar.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\wchar.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\wtime.inl
1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/cpp.h
1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/windowid.h
1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/msw/winundef.h
1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/features.h
1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx\string.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\stdarg.h
1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/wxcrtbase.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\io.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file:  C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\cctype
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\ctype.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\cwctype
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\wctype.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\ctime
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\time.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\time.inl
1>Note: including file:  M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/chartype.h
1>M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/wxcrtbase.h(705) : error C3861: 'strlen': identifier not found
1>M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/wxcrtbase.h(718) : error C3861: '_strdup': identifier not found

7 个答案:

答案 0 :(得分:1)

尝试和/或回答的一些事情:

  • 您是否可以发布至少几行,包括编译器生成“未找到标识符”错误的那一行?
  • 如果您说有一个#include <string.h>行,那么确切地说哪个文件在wx包括哪个文件之前?
  • 使用/showIncludes选项进行构建时,是否可以发布所包含标头的输出(它位于“C / C ++ / Advanced / Show Includes”下的VS 2008 IDE的C ++项目属性页中)?

使用新信息进行修改:

根据您所做的编辑,其中包含/showIncludes中更完整的列表,您可能会错误地设置INCLUDE路径。以下是日志中的几行:

1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\cstring
1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx\string.h

当MSVC的cstring标头试图包含string.h时,它会从string.h库中获取wx标头,而不是编译器分发中的标头(将在C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h)。

我不确定为什么wx库会命名其中一个标题string.h(而不是wxString.h),但我认为它是打算选择的某人使用类似的东西:

#include "wx/string.h"

无论如何,我认为您可以通过确保MSVC include目录位于任何其他目录之前的INCLUDE搜索路径中来解决您的问题。

答案 1 :(得分:0)

如果wxWidgets是C ++,并且它包含并且您的编译器阻止包含和包含cstring / cstdio,那么strlen将在std命名空间而不是全局。尝试使用std :: strlen并查看是否可以修复错误。

答案 2 :(得分:0)

尝试#include<cstdio>#include<cstring>,它们是C ++的标题

答案 3 :(得分:0)

评论字段太小。 我回答迈克尔伯尔:

一个。

#ifdef __cplusplus
inline size_t wxStrlen(const char *s) { return s ? wxCRT_StrlenA(s) : 0; }
inline size_t wxStrlen(const wchar_t *s) { return s ? wcslen(s) : 0; }`

B中。 string.h仅在wxWidgets文件中。

原来的订单是:

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <wctype.h>
#include <time.h>
#include <io.h>

℃。 这里是前面的一些行和第一条错误消息后面的一行:

1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/chartype.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\ctype.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\wctype.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\time.h
1>Note: including file:  C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file:  C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\time.inl
1>Note: including file:  C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\io.h
1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/wxcrtbase.h(696) : error C3861: 'strlen': identifier not found
1>M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/wxcrtbase.h(709) : error C3861: '_strdup': identifier not found

答案 4 :(得分:0)

尝试:

#include <cstdio>
#include <cstring>
#include <cctype>
#include <cwctype>
#include <ctime>
#include <cio>

using namespace std;

#include "wxcrtbase.h"
#include "wx/chartype.h"

int main(void) {
    return strlen("hey there good buddy!");
}

这是我最讨厌c ++的东西。

答案 5 :(得分:0)

我有同样的问题。我的修复方法与包含订单有关。在string.h之前包含stdafx.h会导致错误。相反的方式工作。似乎编译器完全忽略了string.h

答案 6 :(得分:-1)

我的确认为你必须包含cstdio和cstring(如上所述),但在这种情况下,一切都将驻留在命名空间std中,就像std :: strlen一样...