_stricmp 与 mingw 和 c++0x 不存在?
我目前正在尝试将 googletest 与 MinGW 和 -std=c++0x
一起使用,但它抱怨 _stricmp 未在此范围内声明
,而当我这样做时却没有声明不要使用-std=c++0x
。 我不知道 _stricmp
是什么,我只是发现它是在 cstring/string.h
中定义的,那么为什么它在 C++0x 中消失了?
I'm currently trying to use googletest with MinGW and -std=c++0x
but it complains that _stricmp is not declared in this scope
which it doesn't when I do not use -std=c++0x
.
I have no idea what _stricmp
is, I just found out that it is defined in cstring/string.h
, so why is it gone in C++0x?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
-std=c++0x
选项导致 g++ 进入“严格 ANSI”模式,因此它不会声明非标准函数(并且_stricmp()
是非标准函数) -standard - 它只是strcmp()
的一个版本,不区分大小写)。请改用
-std=gnu++0x
。The
-std=c++0x
option causes g++ to go into 'strict ANSI' mode so it doesn't declare non-standard functions (and_stricmp()
is non-standard - it's just a version ofstrcmp()
that's case-insensitive).Use
-std=gnu++0x
instead.除了 Michael 的解决方案之外,还有其他方法可以覆盖
严格 ANSI
模式。在存在编译问题的文件中的任何包含之前包含以下内容:这不仅有助于
_stricmp
,还有助于其他常见函数,例如swptintf
、vswprintf
和 simmilar 。In addition to solution by Michael there is other method for overriding
strict ANSI
mode. Include the following before any includes in file with compilation problems:This helps not only with
_stricmp
also with other common functions likeswptintf
,vswprintf
and simmilar.您可以查看 MinGW-w64,它允许我运行 Google 测试 - std=c++11 (也适用于您的 -std=c++0x )。它消除了 _stricmp、_strdup 等问题。
You can take a look at MinGW-w64, which allowed me to run Google Tests with -std=c++11 (works with your -std=c++0x as well). It eliminates problems with _stricmp, _strdup and so forth.
我遇到了完全相同的问题,但对我来说,我在包含路径中有一个文件
String.h
,该文件由处理器拾取并使用而不是标准一。感谢这个线程。I've had the exact same issue, but for me it was, that I've had a file
String.h
in an include path, that was picked up by the proprocessor and used instead of the standard one. Found thanks to this thread.