HOWTO build old versions of ns-3 on newer compilers

From Nsnam
Jump to: navigation, search

Main Page - Current Development - Developer FAQ - Tools - Related Projects - Project Ideas - Summer Projects

Installation - Troubleshooting - User FAQ - HOWTOs - Samples - Models - Education - Contributed Code - Papers

The build system was changed from Waf to CMake as of ns-3.36 release, and the behavior changed slightly with respect to this HOWTO, so two versions are provided below: 1) Waf-based builds (ns-3.35 and earlier) and 2) CMake-based builds (ns-3.36 and later)

Waf-based builds

ns-3 with Waf builds with the following flags by default: "-Wall -Werror". This causes build warnings to trigger an error and stop the build. This causes problems when trying to build older versions of ns-3 on newer systems with newer compilers, since over time, gcc and clang get more strict.

Since ns-3.29 release, Waf included a configure option to disable the "Werror" flag; in this case, warnings will be emitted but they will not stop the build.

For ns-3.29 through ns-3.35 release, to disable warnings from breaking your build, do the following:

 ./waf configure --disable-werror ...(remainder of your configuration options, if any)
 ./waf build

For ns-3 releases prior to ns-3.29, to disable warnings from breaking your build, do the following:

 CXXFLAGS="-Wall" ./waf configure ...(remainder of your configuration options, if any)
 ./waf build

If you build with the "-vv" option you will observe that all files are built with -Wall and not -Werror; e.g.

 14:16:16 runner system command -> ['/bin/g++', '-Wall', '-fPIC', '-DPIC', '-Idebug', '-I..', '-DNS3_ASSERT_ENABLE', 
 '-DNS3_LOG_ENABLE', '-DNETWORK_SIMULATION_CRADLE', '-DNS3_MODULE_COMPILATION', '../src/common/spectrum-model.cc', 
 '-c', '-o', 'debug/src/common/spectrum-model_1.o']

You may run into other issues (such as missing header files) in trying to build on newer platforms. e.g.

 14:16:16 runner system command -> ['/bin/g++', '-Wall', '-fPIC', '-DPIC', '-Idebug', '-I..', '-DNS3_ASSERT_ENABLE', 
 '-DNS3_LOG_ENABLE', '-DNETWORK_SIMULATION_CRADLE', '-DNS3_MODULE_COMPILATION', '../src/common/spectrum-model.cc', '-c', 
 '-o', 'debug/src/common/spectrum-model_1.o']
 In file included from ../src/common/spectrum-model.cc:22:0:
 debug/ns3/spectrum-model.h:91:3: error: ‘size_t’ does not name a type

This particular error is due to a change in C++ STL; the STL headers no longer incorporate c-style headers, so one must include <cstddef> explicitly.

CMake-based builds

For CMake, there are three build profiles supported: 'optimized', 'default', and 'debug'. Only the 'debug' build profile enables -Werror; therefore, for ns-3.36 and later releases, there should be fewer compilation blockers for users who use the 'default' or 'optimized' build profiles.

For the 'debug' build profile, the "--disable-werror" configuration argument is still available:

 ./ns3 configure -d debug --disable-werror ...(remainder of your configuration options, if any)
 ./ns3 build