Making use of external libraries in NS3

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.

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

 

This entry was posted in 技术 Tech. Bookmark the permalink.

2 Responses to Making use of external libraries in NS3

  1. Ouss says:

    Hi,
    Could you help me please ? I have my program called “rate-adaptation” on NS3 under scratch folder. It runs perfectly. Now, I want to use CPLEX libraries installed in “/opt/ibm/ILOG/CPLEX_Studio127/” from my program. The problem is that I get the error:
    ../scratch/rate-adaptation/server.h:22:26: fatal error: ilopl/iloopl.h: No such file or directory

    Couldu you please tell me what is wrong ?

    My wscript file under scratch/rate-adaptation looks like :
    def configure(conf):
    conf.env[“ENABLE_opl”]=conf.check(mandatory=True,
    libpath=[“/opt/ibm/ILOG/CPLEX_Studio127/opl/lib/x86-64_linux/static_pic”],
    includes=[“/opt/ibm/ILOG/CPLEX_Studio127/opl/include”],
    lib=”opl”,uselib_store=”LIB_OPL”)

    def build(bld):
    obj = bld.create_ns3_program(‘rate-adaptation’, [‘core’, ‘stats’, ‘point-to-point’, ‘internet’, ‘applications’])
    obj.source = ‘rate-adaptation.cc’
    module.use.append(“LIB_OPL”)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.