【发布时间】:2011-07-31 05:37:40
【问题描述】:
我有一些 C++0x 代码。我能够在下面重现它。下面的代码在没有-std=c++0x 的情况下也能正常工作,但是我需要它作为我的真实代码。
如何在 C++0x 中包含 strdup?使用 gcc 4.5.2
注意我正在使用 mingw。我尝试包括 cstdlib、cstring、string.h 并尝试使用 std::。没有运气。
>g++ -std=c++0x a.cpp
a.cpp: In function 'int main()':
a.cpp:4:11: error: 'strdup' was not declared in this scope
代码:
#include <string.h>
int main()
{
strdup("");
return 0;
}
【问题讨论】:
-
适用于 gcc 4.5.1。尝试
#include` 并使用 std::strdup,这就是“C++ 方式”。 (但仍然不是答案,因为这也应该是有效的,IIRC。) -
@GMan:我修改了我的问题。我试过了,但没有运气:(。作为临时解决方案,我将 extern C
_CRTIMP char* __cdecl __MINGW_NOTHROW strdup (const char*) __MINGW_ATTRIB_MALLOC;放在我的标题中。它适用于此。
标签: gcc c++11 g++ compiler-errors strdup