使用 c++0x 在 g++ 上出现 strdup 错误 [英] strdup error on g++ with c++0x

查看:19
本文介绍了使用 c++0x 在 g++ 上出现 strdup 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些 C++0x 代码.我能够在下面重现它.下面的代码在没有 -std=c++0x 的情况下工作正常,但是我的真实代码需要它.

I have some C++0x code. I was able to reproduce it below. The code below works fine without -std=c++0x however i need it for my real code.

我如何在 C++0x 中包含 strdup?使用 gcc 4.5.2

How do i include strdup in C++0x? with gcc 4.5.2

注意我正在使用 mingw.我尝试包括 cstdlib、cstring、string.h 并尝试使用 std::.没有运气.

note i am using mingw. i tried including cstdlib, cstring, string.h and tried using std::. No luck.

>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;
}

推荐答案

-std=gnu++0x(而不是 -std=c++0x)对我有用;-D_GNU_SOURCE 不起作用(我尝试使用交叉编译器,但也许它适用于其他类型的 g++).

-std=gnu++0x (instead of -std=c++0x) does the trick for me; -D_GNU_SOURCE didn't work (I tried with a cross-compiler, but perhaps it works with other kinds of g++).

似乎默认值(没有 -std=... 传递)是GNU C++"而不是严格的标准 C++",因此除了升级到 C++11 之外,不要更改任何内容"的标志是-std=gnu++0x,不是-std=c++0x;后者的意思是升级到 C++11 并且比默认情况下更严格".

It appears that the default (no -std=... passed) is "GNU C++" and not "strict standard C++", so the flag for "don't change anything except for upgrading to C++11" is -std=gnu++0x, not -std=c++0x; the latter means "upgrade to C++11 and be stricter than by default".

这篇关于使用 c++0x 在 g++ 上出现 strdup 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆