21

我目前正在尝试将 googletest 与 MinGW 一起使用,-std=c++0x但它抱怨_stricmp is not declared in this scope我不使用-std=c++0x. 我不知道是什么_stricmp,我刚刚发现它是在 中定义的cstring/string.h,那为什么它在 C++0x 中消失了?

4

3 回答 3

24

-std=c++0x选项导致 g++ 进入“严格 ANSI”模式,因此它不声明非标准函数(并且_stricmp()是非标准的 - 它只是strcmp()不区分大小写的版本)。

改为使用-std=gnu++0x

于 2011-06-10T21:43:00.100 回答
7

除了迈克尔的解决方案之外,还有其他方法可以覆盖strict ANSI模式。在任何包含编译问题的文件中包含以下内容:

#ifdef __STRICT_ANSI__
#undef __STRICT_ANSI__
#endif

这不仅有助于_stricmp其他常见功能,如swptintf,vswprintf和 simmilar。

于 2013-05-09T22:52:42.843 回答
1

您可以查看MinGW-w64,它允许我使用 -std=c++11 运行 Google 测试(也适用于您的 -std=c++0x)。它消除了 _stricmp、_strdup 等问题。

于 2018-10-15T20:27:17.343 回答