There are have been some articles introducing how to make used of external libraries in NS3, such as
HOWTO use ns-3 with other libraries
https://www.nsnam.org/wiki/HOWTO_use_ns-3_with_other_libraries
Extending NS3 with your module and extra libraries
http://shieldroute.blogspot.fr/2012/08/extending-ns3-with-your-module-and.html
But they are not very straightforward, or it took me a little while to make it work. So I’ll simply repass the HOWTO with more details here.
- The first step is, of course, make your own libraries or the third-party library ready. If you want to build your own libraries, you can check
Static, Shared Dynamic and Loadable Linux Libraries http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html
Assuming now we have a static library named libctest.a and header file ctest.h.
2. In the wscript file of your module, add the following code:
def configure(conf):
conf.env[‘ENABLE_ctest‘]=conf.check(mandatory=True,
libpath=[‘PATH-TO-YOUR-LIB‘],
includes=[‘PATH-TO-YOUR-HEADER-FILES‘],
lib=’ctest‘,uselib_store=’LIB_CTEST‘)
And
def build(bld):
…
module.use.append(“LIB_CTEST”)
…
ATTENTION: the file names and lib names are important!!
If you are using third party libraries, you probably need to define the LD_* variables accordingly.
3. Reconfigure and rebuild ns3 with, if it’s a static library
./waf configure –enable-static
and then
./waf build
4. In the code where you need to make used of the library, include the header files like:
extern “C”{ //we are using c here
#include <ctest.h>
}
Now you can make used of the functions defined in the lib.