HOWTO use ns-3 with other libraries

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

Note: The below documentation may be outdated; a bug (#1490) has been filed, and in the meantime, please see a recent blog post about this topic:

If you develop a new module that requires use of other system libraries, you will want the waf build system to find the appropriate headers and libraries. This is a brief note of how you might do this, motivated by this ns-3-users thread.

For example, suppose the new module requires these flags:

 g++ -Wall -O3 -fopenmp -DLAPACK -DLUSOLVER=LAPACK GenrFail.o sim.o -
 L../../src -lthyme -llapack -L/usr/local/src/GotoBLAS2 -lblas 

You can specify some extensions in your wscript such as:

 conf.env.append_value("CXXFLAGS", ["-Wall", "-O3", "-fopenmp"])
 conf.env.append_value("CXXDEFINES", ["LAPACK", "LUSOLVER=LAPACK"])
 conf.env.append_value("LINKFLAGS", ["-llapack", "-L/usr/local/src/GoToBLAS2", "-lblas", "-Lsrc/common", "-lthyme"])

Make sure to replace CXX with CC if you are compiling C sources instead of C++ ones.

There are some environment variables that can be set to apply flags to the whole build, if you do not care about adding them to all compilation units. In the top-level wscript:

   # append user defined flags after all our ones
   for (confvar, envvar) in [['CCFLAGS', 'CCFLAGS_EXTRA'],
                             ['CXXFLAGS', 'CXXFLAGS_EXTRA'],
                             ['LINKFLAGS', 'LINKFLAGS_EXTRA'],
                             ['LINKFLAGS', 'LDFLAGS_EXTRA']]:

So, a command such as:

 CXXFLAGS_EXTRA="-fopenmp" ./waf build

will get the openmp flag appended.

Finally, another example of how to add a library can be found in the wifi device, and the approach could be copied. Some files in src/devices/wifi depend on GNU Scientific Library (GSL), and when GSL is installed, we want to use it. We want -lgsl -lm -lgslcblas to be appended. In the src/devices/wifi/wscript, you can see this:

  if bld.env['ENABLE_GSL']:
        obj.uselib = 'GSL GSLCBLAS M'

where ENABLE_GSL is set in the top-level wscript (search for "have_gsl" in the top wscript where the configuration check is done).