How to integrate external libraries into ns3 using waf build system?

224 views
Skip to first unread message

Harshal Dev

unread,
Aug 3, 2021, 8:40:25 AM8/3/21
to ns-3-users
Hello,

I am trying to integrate the IBM CPLEX external library into ns3. In order to run a C++ based CPLEX optimization program, the manual says I must supply the paths to the library to allow for compilation and linking.

I was wondering if it is possible to do this using the waf build system in ns3?

Some insights would be truly appreciated.

Thanks

Lu Zhao

unread,
Oct 31, 2022, 12:35:49 PM10/31/22
to ns-3-users
Hello,

I have had the same problem.
I was wondering whether it is resolved. If resolved, could you please share some insights on how to do?

Thanks

Tom Henderson

unread,
Nov 1, 2022, 8:47:34 AM11/1/22
to ns-3-...@googlegroups.com, Lu Zhao
ns-3 now uses CMake instead of Waf, and Gabriel has written about how to
link external libraries in the manual:

https://www.nsnam.org/docs/manual/html/working-with-cmake.html#linking-third-party-libraries
> --
> Posting to this group should follow these guidelines
> https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
> <https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting>
> ---
> You received this message because you are subscribed to the Google
> Groups "ns-3-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to ns-3-users+...@googlegroups.com
> <mailto:ns-3-users+...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ns-3-users/1d3e4cf2-8103-42b1-83ed-8255342cd021n%40googlegroups.com <https://groups.google.com/d/msgid/ns-3-users/1d3e4cf2-8103-42b1-83ed-8255342cd021n%40googlegroups.com?utm_medium=email&utm_source=footer>.

Lu Zhao

unread,
Nov 7, 2022, 12:50:00 PM11/7/22
to ns-3-users
Hi Tom,

Thanks for your response and providing the valuable information. I really appreciate it.

I have my project built upon ns-3.26 which uses Waf.
I have followed the instructions from Wiki (https://www.nsnam.org/wiki/HOWTO_use_ns-3_with_other_libraries) and also searched for other possible ways for resolving the problem, but the project cannot be built successfully.
Could you please provide some insights on how to use Waf to link external libraries with one of the module, e.g., 'application'?

In addition, if using CMake, one problem for linking the CPLEX external library into ns3 is that I need two libraries to use certain optimization functions, and one of the two libraries is dependent on the other one (e.g., 'cplex' and 'concert' in CPLEX studio 221).
How can I deal with the case? It seems that this has not been mentioned in the manual.

Thanks,
Lu

Veerendra Kumar Gautam

unread,
Dec 11, 2022, 10:11:16 AM12/11/22
to ns-3-users
//Change wscript in application or where you are using cplex code . first install cplex on your system then call the library .

// check out these links.

## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-

def configure(conf):
conf.env.append_value("CXXFLAGS", [
"-Wno-error",
"-m64",
"-O0",
"-fPIC",
"-fno-strict-aliasing",
"-fexceptions",
"-DNDEBUG",
"-DIL_STD",
"-I/opt/ibm/ILOG/CPLEX_Studio1210/concert/include",
"-I/opt/ibm/ILOG/CPLEX_Studio1210/cplex/include"])



conf.env.append_value("LINKFLAGS", [
"-L/opt/ibm/ILOG/CPLEX_Studio1210/cplex/lib/x86-64_linux/static_pic",
"-L/opt/ibm/ILOG/CPLEX_Studio1210/concert/lib/x86-64_linux/static_pic",
"-lilocplex",
"-lconcert",
"-lcplex",
"-lm",
"-lpthread"])

conf.env['lconcert'] = conf.check(mandatory=True, lib='concert', uselib_store='CONCERT')
conf.env['lilocplex'] = conf.check(mandatory=True, lib='ilocplex', uselib_store='ILOCPLEX')
conf.env['lcplex'] = conf.check(mandatory=True, lib='cplex', uselib_store='CPLEX')

def build(bld):
module = bld.create_ns3_module('applications', ['internet', 'config-store','stats'])
module.source = [
'model/bulk-send-application.cc',
'model/onoff-application.cc',
'model/packet-sink.cc',
'model/udp-client.cc',
'model/udp-server.cc',
'model/udp-offload-server.cc',
'model/udp-offload-client.cc',
'model/maxrate.cc',
'model/seq-ts-header.cc',
'model/seq-ts-size-header.cc',
'model/size-header.cc',
'model/udp-trace-client.cc',
'model/udp-offload-trace-client.cc',
'model/packet-loss-counter.cc',
'model/udp-echo-client.cc',
'model/udp-echo-server.cc',
'model/application-packet-probe.cc',
'model/three-gpp-http-client.cc',
'model/three-gpp-http-server.cc',
'model/three-gpp-http-header.cc',
'model/three-gpp-http-variables.cc',
'model/myheader.cc',
'model/mytag.cc',
'model/responseheader.cc',
'helper/bulk-send-helper.cc',
'helper/on-off-helper.cc',
'helper/packet-sink-helper.cc',
'helper/udp-client-server-helper.cc',
'helper/udp-offload-client-server-helper.cc',
'helper/udp-echo-helper.cc',
'helper/three-gpp-http-helper.cc',
]

applications_test = bld.create_ns3_module_test_library('applications')
applications_test.source = [
'test/three-gpp-http-client-server-test.cc',
'test/udp-client-server-test.cc'
]

headers = bld(features='ns3header')
headers.module = 'applications'
headers.source = [
'model/bulk-send-application.h',
'model/onoff-application.h',
'model/packet-sink.h',
'model/udp-client.h',
'model/udp-server.h',
'model/udp-offload-client.h',
'model/udp-offload-server.h',
'model/seq-ts-header.h',
'model/seq-ts-size-header.h',
'model/size-header.h',
'model/udp-trace-client.h',
'model/udp-offload-trace-client.h',
'model/packet-loss-counter.h',
'model/udp-echo-client.h',
'model/udp-echo-server.h',
'model/application-packet-probe.h',
'model/three-gpp-http-client.h',
'model/three-gpp-http-server.h',
'model/three-gpp-http-header.h',
'model/three-gpp-http-variables.h',
'model/mytag.h',
'model/myheader.h',
'model/responseheader.h',
'helper/bulk-send-helper.h',
'helper/on-off-helper.h',
'helper/packet-sink-helper.h',
'helper/udp-client-server-helper.h',
'helper/udp-offload-client-server-helper.h',
'helper/udp-echo-helper.h',
'helper/three-gpp-http-helper.h'
]

module.use.append("CONCERT")
module.use.append("ILOCPLEX")
module.use.append("CPLEX")

if (bld.env['ENABLE_EXAMPLES']):
bld.recurse('examples')

bld.ns3_python_bindings()


Veerendra Kumar Gautam

unread,
Dec 11, 2022, 10:14:36 AM12/11/22
to ns-3-users
But i dont know how to use it with cmake. I am trying for cmake with 3.36 version of NS-3. I will post the code as soon as i will resolve this issue.

Lu Zhao

unread,
Jan 3, 2023, 10:48:08 AM1/3/23
to ns-3-users
Thank you so much for your help.

Best,
Lu

eguadocalor

unread,
Jan 27, 2023, 3:43:59 PM1/27/23
to ns-3-users
Dear all,

The following question might fit in this thread subject.
So, does anybody has a hint on how the following wscript snippet could be "translated"  into the new cmake pattern?

wscrip 1:
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"])


wscrip 2:
conf.env.append_value('CXXFLAGS', '-I/usr/local/include/e2sim')
conf.env.append_value("LINKFLAGS", ["-L/usr/local/lib"])
conf.env.append_value("LIB", ["e2sim"])


The above snippet shall be written in two different CMakeLists.txt files once each represents two different ns-3 modules.
I couldn't find a proper way to do so when checking the documentation.
I appreciate.

Gabriel Ferreira

unread,
Jan 27, 2023, 9:32:37 PM1/27/23
to ns-3-users
Set the following before declaring your targets.

wscrip 1
conf.env.append_value("CXXFLAGS", ["-Wall", "-O3", "-fopenmp"]) => wall and O3 are managed somewhere else. `add_compile_options(-fopenmp)`
conf.env.append_value("CXXDEFINES", ["LAPACK", "LUSOLVER=LAPACK"]) => `add_compile_definitions(-DLAPACK -DLUSOLVER=LAPACK)`
conf.env.append_value("LINKFLAGS", ["-llapack", "-L/usr/local/src/GoToBLAS2", "-lblas", "-Lsrc/common", "-lthyme"]) => `link_directories(/usr/local/src/GoToBLAS2  ./src/common)`
                                                                                                                                                                                                               and either append libraries to the LIBRARIES_TO_LINK list of your target, 
                                                                                                                                                                                                               or use `link_libraries(lapack blas thyme)`

wscript2
conf.env.append_value('CXXFLAGS', '-I/usr/local/include/e2sim') => `include_directories(/usr/local/include/e2sim)`
conf.env.append_value("LINKFLAGS", ["-L/usr/local/lib"]) => `link_directories(/usr/local/lib)`
conf.env.append_value("LIB", ["e2sim"]) => append e2sim to the LIBRARIES_TO_LINK list your target, or just use `link_libraries(e2sim)`


The recommended way to handle these is find_external_library

find_external_library(
  DEPENDENCY_NAME GoToBLAS2 
  HEADER_NAMES lapack.h blas.h thyme.h
  LIBRARY_NAMES lapack blas thyme 
  SEARCH_PATHS src/common
)

if(${GoToBLAS2_FOUND}) 
    add_compile_options(-fopenmp)
    add_compile_definitions(-DLAPACK -DLUSOLVER=LAPACK)
    include_directories(${GoToBLAS2_INCLUDE_DIRS})
    link_libraries(${GoToBLAS2_LIBRARIES})
    build_lib( 
        LIBNAME wscript_1_module
        LIBRARIES_TO_LINK ${GoToBLAS2_LIBRARIES} ) 
endif()




find_external_library(
  DEPENDENCY_NAME e2sim
  HEADER_NAMES e2sim.h
  LIBRARY_NAME e2sim
)

if(${e2sim_FOUND}) 
    include_directories(${e2sim_INCLUDE_DIRS})
    link_libraries(${e2sim_LIBRARIES})
    build_lib( 
        LIBNAME wscript_2_module
        LIBRARIES_TO_LINK ${e2sim_LIBRARIES} ) 
endif()

Reply all
Reply to author
Forward
0 new messages