1

I am writing a C++ program for Network Simulator 3, and I want to use C++14 experimental std::optional. I was compiling my code with gcc5 until I saw a warning like

/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.

Then I searched for the gcc version that had C++14 as the default standard which is gcc6 (https://gcc.gnu.org/gcc-6/porting_to.html) and I installed it. Typing gcc -v outputs version 6.3 .

But the problem is that the error is still there and I don't know what steps to follow next. Can anyone give me hints on how to solve the problem or what else I should try?

My operating system is Ubuntu desktop 16.04.

Edit:

I think it is a ns3 problem, I have created a minimal working example:

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

using namespace std;

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

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

and it compiles as "expected", with just a little note that this feature is experimental. I have tried to add every type of flag to ns3 but still doesn't compile and outputs the same message.

g++ -v outputs:

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)
vicaba
  • 2,836
  • 1
  • 27
  • 45
  • @IgnacioVazquez-Abrams No, I have read the message, the thing is that if C++14 is the standard, why is outputing this message? – vicaba Nov 08 '17 at 12:31
  • @IgnacioVazquez-Abrams OP has read the message and provided in their question the root of their interrogation: according to GCC doc, that version handle C++14 but a file from its Standard Library implementation says otherwise. – YSC Nov 08 '17 at 12:38
  • std::optional did not make it into C++14, however it is being standardized in C++17. Did you try compiling with -std=c++1z? – PaulR Nov 08 '17 at 12:39
  • 3
    Can we have a [mcve]: the minimal include to make to get this error? – YSC Nov 08 '17 at 12:39
  • In the complaing file, it has the line: `#if __cplusplus <= 201103L` what means that the compiler is not being recognized as C++14. You could try passing, explicitly, this directive to g++: `g++ -std=c++14` – Amadeus Nov 08 '17 at 12:40
  • Can you show us the command line you are using to compile your project? Are you using a Makefile? Also, just curious what does `g++ -v` output? – AresCaelum Nov 08 '17 at 12:42
  • @Amadeus thanks for the info, then ns3 is not using the "default" compiler, as g++ -v outputs version 6.3 – vicaba Nov 08 '17 at 13:03
  • @Eddge I have updated my answer, it seems that compiling the mwe with g++ outputs a nota, so it is fine, but ns3 (Network Simulator 3) does not use the proper compiler. It uses the waf build system. I am a little lost here, so maybe it is better to ask ns3 developers. – vicaba Nov 08 '17 at 13:05

2 Answers2

1

There is a pending patch to ns-3 to fix this; it should show up in a future ns-3 release (ns-3.28) or the patch can be applied to the current and earlier releases: https://www.nsnam.org/bugzilla/show_bug.cgi?id=2800

0

It seems like the flag -std=c++11 is hardcoded in the root wscript file of ns3. This answer helped me to change it How to specify gcc flags (CXXFLAGS) particularly for a specific module? .

vicaba
  • 2,836
  • 1
  • 27
  • 45