我需要在网络模拟器 NS-3 的代码中使用像 unordered_map 这样的数据结构。 它使用waf builder编译源代码。 我很困惑我应该在哪里添加 -std=c++0x 以添加到编译器标志? 我尝试使用以下方法将它附加到主 wscript 文件中的 CXXFlags:
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
我还应该向我的 waf 模块添加任何库吗?
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.
有没有办法告诉编译器使用 0x 而不是 11?
最佳答案
解决方法如下:
首先将Ns-3的GCC升级到4.7会因为标准的变化导致更多的错误,并不能解决问题。所以我将 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
关于c++ - 如何构建 NS-3 以使用 C++0x/C++11 库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11876088/