2012-08-09 50 views
4

我需要在网络模拟器NS-3的代码中使用像unordered_map这样的数据结构。 它使用waf生成器来编译源代码。 我很困惑,我应该在哪里添加-std = C++ 0x来添加到编译器标志中? 我尝试了用追加到主文件的WScript CXXFLAGS:如何构建NS-3以使用C++ 0x/C++ 11库?

module.env.append_value('CXXFLAGS', '-std=c++0x'); 

但是还是我收到此错误:

This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options. C/C++ Problem

我应该还的任何库添加到我的网络应用防火墙模块呢?

P.S:我的GCC的版本是4.4

更新:更新到4.7后,我得到这个错误:

error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options. 

有没有办法告诉编译器使用,而不是11 0X?

+4

你有没有考虑使用GCC版本,这是最近2年以上走? – 2012-08-09 03:57:13

+1

尝试获得GCC的新版本(如果使用C++ 11,我会说*至少* 4.6,但是甚至4.7.1)。 – Geoffroy 2012-08-09 07:52:19

+0

@NicolBolas我更新了我的GCC和G ++到4.7并重新配置NS,但现在当它达到同一点时,它会出现此错误:error:#error该文件需要编译器和库支持ISO C++ 2011标准。此支持目前是实验性的,必须使用-std = C++ 11或-std = gnu ++ 11编译器选项启用。 – hashtpaa 2012-08-09 20:00:10

回答

8

这里是解决方案:

首先升级GCC到4.7 NS-3会导致更多的错误是由于标准的变化,不解决问题。所以我将gcc和g ++改回4.4.3。

但为了摆脱这种错误的(因为它说的)这个选项应该加入CXXFLAGS:

-std=c++0x 

要添加一个选项CXXFLAG您可以使用此:

CXXFLAGS="-std=c++0x" ./waf configure 

或者如果你想添加选项到WAF配置:

CXXFLAGS="-std=c++0x" ./waf -d debug --enable-examples --enable-tests configure