【问题标题】:NS3 - G++ 6.x warning about c++14NS3 - G++ 6.x 关于 c++14 的警告
【发布时间】:2017-11-08 12:27:54
【问题描述】:

我正在为 Network Simulator 3 编写 C++ 程序,我想使用 C++14 实验性 std::optional。我正在用 gcc5 编译我的代码,直到我看到类似

的警告
/usr/include/c++/6/bits/c++14_warning.h:32:2: error: #error This file requires compiler and library support for the forthcoming ISO C++ 2014 standard. This support is currently experimental, and must be enabled with the -std=c++1y or -std=gnu++1y compiler options.

然后我搜索了以 C++14 作为默认标准的 gcc 版本,即 gcc6 (https://gcc.gnu.org/gcc-6/porting_to.html) 并安装了它。输入 gcc -v 输出版本 6.3。

但问题是错误仍然存​​在,我不知道接下来要执行什么步骤。谁能给我一些关于如何解决问题或我应该尝试什么的提示?

我的操作系统是 Ubuntu 桌面 16.04。

编辑:

我认为这是一个 ns3 问题,我创建了一个最小的工作示例:

#include <iostream>
#include <experimental/optional>

using namespace std;

// main() is where program execution begins.
int main() {

   cout << "Hello World"; // prints Hello World
   return 0;
}

它编译为“预期的”,只需注意此功能是实验性的。我尝试将每种类型的标志添加到 ns3,但仍然无法编译并输出相同的消息。

g++ -v 输出:

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 6.3.0-18ubuntu2~16.04' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 6.3.0 20170519 (Ubuntu/Linaro 6.3.0-18ubuntu2~16.04)

【问题讨论】:

  • @IgnacioVazquez-Abrams 不,我已经阅读了消息,问题是如果 C++14 是标准,为什么会输出此消息?
  • @IgnacioVazquez-Abrams OP 已阅读该消息并在他们的问题中提供了他们审讯的根源:根据 GCC 文档,该版本处理 C++14,但其标准库实现中的文件另有说明.
  • std::optional 没有进入 C++14,但是它在 C++17 中被标准化。您是否尝试使用 -std=c++1z 进行编译?
  • 我们可以有一个minimal reproducible example:得到这个错误的最小包含吗?
  • 在投诉文件中,它有一行:#if __cplusplus &lt;= 201103L 这意味着编译器未被识别为 C++14。您可以尝试将此指令明确地传递给 g++:g++ -std=c++14

标签: c++ compiler-errors g++ ns-3


【解决方案1】:

ns-3 有一个待定的补丁来解决这个问题;它应该出现在未来的 ns-3 版本 (ns-3.28) 中,或者补丁可以应用于当前和早期版本: https://www.nsnam.org/bugzilla/show_bug.cgi?id=2800

【讨论】:

    【解决方案2】:

    似乎标志 -std=c++11 被硬编码在 ns3 的根 wscript 文件中。这个答案帮助我改变了它How to specify gcc flags (CXXFLAGS) particularly for a specific module?

    【讨论】:

      猜你喜欢
      • 2017-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-11
      • 1970-01-01
      • 1970-01-01
      • 2013-05-25
      相关资源
      最近更新 更多