C++ 'strcasecmp' 未在此范围内声明

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7248509/
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-28 16:40:59  来源:igfitidea点击:

‘strcasecmp’ was not declared in this scope

c++

提问by merveotesi

I am trying to build a source code called lipiTk

我正在尝试构建一个名为 lipiTk 的源代码

I have lots of errors like this:

我有很多这样的错误:

Documents/lipi/lipi/src/reco/shaperec/activedtw/ActiveDTWShapeRecognizer.cpp:1222:78: 
 error: ‘strcasecmp' was not declared in this scope

What should I do, there is too many cpp file in the code that gives similar errors. I do not think i can test with writing include string.h into every cpp file that gives error, might the problem be about my compiler?

我该怎么办,代码中的cpp文件太多,出现类似错误。我不认为我可以通过将 include string.h 写入每个出错的 cpp 文件来进行测试,问题可能出在我的编译器上吗?

I am on Ubuntu and GCC is 4.5.

我在 Ubuntu 上,GCC 是 4.5。

My sw configuration is upper than lipitk needs as I read in manual.

正如我在手册中阅读的那样,我的 sw 配置高于 lipitk 的需求。

回答by Ed Heal

I think that it may be doing

我认为它可能正在做

#include <string>

The errors should be fixed if you change it to

如果您将其更改为,则应该修复错误

#include <strings.h>

回答by James Curran

I'm gonna guess here. "strcasecmp" is not a standard library function, however, it name follows the convention of library function, so I imagine that lipiTk was originally written using some compiler which added a bunch of non-standard extensions to it's run-time library (and declared them in the standard header files)

我会在这里猜测。“strcasecmp”不是标准库函数,但是,它的名称遵循库函数的约定,所以我想 lipiTk 最初是使用一些编译器编写的,该编译器向它的运行时库添加了一堆非标准扩展(并声明它们在标准头文件中)

So, I'd guess that the problem is that your compiler has a different set of library extension --or maybe similar ones with different names -- Google tells me that "strcasecmp" does a case-insensitive string comparison, which many compilers call "stricmp" or "strcmpi" or "_stricmp". Figure out which name your compiler uses then add a #define at the top of the source file:

所以,我猜问题是你的编译器有一组不同的库扩展——或者可能有不同名称的类似库扩展——谷歌告诉我“strcasecmp”做了一个不区分大小写的字符串比较,许多编译器称之为“stricmp”或“strcmpi”或“_stricmp”。找出您的编译器使用的名称,然后在源文件的顶部添加 #define:

#define strcasecmp _stricmp

回答by jweyrich

As I mentioned in comments earlier, strcasecmpis not in the C or C++ standard. However, it's defined by POSIX.1-2001 and 4.4BSD.

正如我之前在评论中提到的,strcasecmp不在 C 或 C++ 标准中。但是,它是由 POSIX.1-2001 和 4.4BSD 定义的。

Assuming your system is POSIX or BSD compliant, you must include the correct header:

假设您的系统符合 POSIX 或 BSD,您必须包含正确的标头:

#include <strings.h>

回答by John Humphreys - w00te

You need to include the file for the function to be available in the scope - how in the world did you get so much code without the correct inclusions in it (I'm assuming its alot if you can't put that in every file once).

您需要包含该函数的文件才能在作用域中使用 - 在没有正确包含的情况下,您究竟是如何获得这么多代码的(如果您不能将其放入每个文件一次,我假设它很多)。

PS: Are you sure your ubuntu version has that function available in string.h? type:

PS:您确定您的 ubuntu 版本在 string.h 中有该功能吗?类型:

man strcasecmp

into a bash terminal to see if its there and how to access it. That might help you find where it is at least assuming your code's right and the includes are just off from porting or something like that.

进入 bash 终端以查看它是否存在以及如何访问它。这可能会帮助您找到它至少在假设您的代码是正确的并且包含刚刚从移植或类似的地方。