You can compile and link your NS3 program with an external library. For example, your program “mysrc.cc” is under
NS3-BASE-DIR/examples/myapp/mysrc.cc
and you want to link to, e.g., a static library named “libfoo.a” that is under ~/LIBDIR/lib directory
and library header file exists under ~/LIBDIR/include.
First include the library header file into your “mysrc.cc” as
#include<foo.h>
Now open the NS3-BASE-DIR/examples/myapp/wscript and add build information for your program as follows
def build(bld): obj = bld.create_ns3_program('prog_name', ['core', 'network', """... modules your program depends on"""]) obj.source = 'mysrc.cc' obj.env.append_value("CXXFLAGS", "-I/Absolute-path-to-LIBDIR/include") obj.env.append_value("LINKFLAGS", ["-L/Absolute-path-to-LIBDIR/lib"]) obj.env.append_value("LIB", ["foo"])
This method is tested on NS-3.15.
This is a life saver! It’s unbelievable how hard it gets to make ns-3’s build system play nice
wow….. soooo amazing…..
Brilliant!!!!!! This is still working for the latest ns-3. Thanks a lot! Be blessed!
Could you help me?
I´m trying to link the openssl library to ns3 but I cant make it work
Thank you very much!
To link with dynamic library (*.so), you have to modify the LINKFLAGS as follows
obj.env.append_value(“LINKFLAGS”,
[“-L/Absolute-path-to-LIBDIR/lib”,
“-Wl, -rpath, /Absolute-path-to-LIBDIR/lib”])
See this post http://wp.me/p2engI-35
Hope it helps.