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

查看:200
本文介绍了使用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

code:

code:

#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++).

看起来,缺省值(no -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天全站免登陆