C++ 标题正确,但未找到标识符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2526659/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 23:49:09  来源:igfitidea点击:

Header correct, but identifier not found

c++cvisual-studio-2008

提问by sciloop

I have two projects (x64).

我有两个项目(x64)。

A. Written in C (wxWidgets) --- edit: its in C++!

一个。用 C (wxWidgets) 编写 --- 编辑:它是用 C++ 编写的!

B. Written in C++

。用 C++ 编写

Acompiles fine, but B(which uses functions of A) gives several errors when I try to compile.

A编译得很好,但是当我尝试编译时B(它使用A 的函数)给出了几个错误。

I suggest that the reason for the errors is the same for all, so I mention only the first. It says:

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

strlen: identifier not found

In the file which gives the error messages ( wxcrtbase.h ), the following headers are included:

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

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

The files from Binclude the following headers from A:

来自B的文件包括来自A的以下标头:

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

So, currently, I have no idea where to start to search for the reason of the errors. May it be that I have C and C++ files? Maybe that I compiled for x64?

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

Thanks for help!

感谢帮助!

edit: more info
the lines in wxcrtbase.h around the one producing the first error message are:

编辑:更多信息
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; }  

The order of the includes of the wxcrtbase.h is

wxcrtbase.h 的包含顺序是

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

The /showIncludes lists the following ( I stop with the list after the first two error messages ):

/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

回答by Michael Burr

A few things to try and/or answer:

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

  • Can you post at least the few lines around and including the one that the compiler generates the 'identifier not found' error?
  • When you say you have an #include <string.h>line, exactly which file(s) and does it precede the various wxincludes?
  • Can you post the output of the included headers when you build with the /showIncludesoption (it's in the VS 2008 IDE's C++ project property page under "C/C++/Advanced/Show Includes")?
  • 您能否至少发布几行并包括编译器生成“未找到标识符”错误的那一行?
  • 当您说您有#include <string.h>一行时,确切地说是哪个文件以及它是否位于各种wx包含之前?
  • 当您使用该/showIncludes选项构建时,您能否发布包含的头文件的输出(它在 VS 2008 IDE 的 C++ 项目属性页中的“C/C++/Advanced/Show Includes”下)?


Edit, with new information:

编辑,提供新信息:

Based on the edit you made that included a more complete listing from /showIncludes, it appears that you might have the INCLUDE path set incorrectly. Here are a couple of lines from the log:

根据您所做的包含来自 的更完整列表的编辑/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

When MSVC's cstring header is trying to include string.h, it's picking up a string.hheader from the wxlibrary instead of the one that's part of the compiler distribution (which would be in C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h).

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

I'm not sure why the wxlibrary would name one of their own headers string.h(instead of, say, wxString.h), but I assume that it's intended to be picked up by someone using something like:

我不知道为什么wx图书馆会命名他们自己的标题之一string.h(而不是,比如说,wxString.h),但我认为它旨在被某人使用以下内容获取:

#include "wx/string.h"

Regardless, I think you'll fix your problem by making sure that the MSVC include directory is in the INCLUDE search path before any other directory.

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

回答by sciloop

The comment field is too small. I answer to Michael Burr:

评论栏太小了。我回答迈克尔·伯尔:

A.

一种。

#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. the string.h is only in the wxWidgets files.

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

There the original order is:

原来的顺序是:

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

C. Here`s the some lines before and a line after the first error message:

C. 这是第一条错误消息之前的几行和之后的几行:

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

回答by nategoose

Try:

尝试:

#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!");
}

This is the stuff that I hate about c++ the most.

这是我最讨厌 C++ 的地方。

回答by Mark B

If wxWidgets is C++, and it includes and and your compiler prevents inclusion of and when cstring/cstdio are included, then strlen would be in the std namespace instead of global. Try std::strlen and see if that fixes the error.

如果 wxWidgets 是 C++,并且它包含 and 并且您的编译器阻止包含 and 当包含 cstring/cstdio 时,则 strlen 将位于 std 命名空间中而不是全局命名空间中。尝试 std::strlen 并查看是否修复了错误。

回答by gc .

Try #include<cstdio>and #include<cstring>, which are the headers for C++

Try #include<cstdio>and #include<cstring>,它们是 C++ 的头文件

回答by JamLan

I had this same problem. The fix for me had to do with the include order. Including string.hbefore stdafx.hcaused the error. The other way around works. It seems that the compiler was ignoring string.hcompletely.

我有同样的问题。我的修复与包含顺序有关。包括string.h之前stdafx.h导致的错误。反过来工作。似乎编译器完全忽略string.h了。

回答by Randall Flagg

I indeed think that you have to include cstdio and cstring (as proposed above), but in this case everything will reside in namespace std, like std::strlen and such...

我确实认为您必须包含 cstdio 和 cstring(如上所述),但在这种情况下,所有内容都将驻留在命名空间 std 中,例如 std::strlen 等...