Linking error when adding external library to ns3 module

471 views
Skip to first unread message

Harshal Dev

unread,
Sep 2, 2021, 5:27:51 AM9/2/21
to ns-3-users
Hi,

I have been trying to add the CPLEX library to the ns3 wifi module from a while, and I have gone through all these threads [1-2] along with these two tutorials [3-4] in particular (suggested on the HOW-TO wiki page to get some idea).


In order to compile and create a binary for a file that uses the CPLEX library, the following flags are necessary:
'-g', '-m64', '-fPIC', '-fno-strict-aliasing', '-fexceptions', '-DNDEBUG', '-I/opt/ibm/ILOG/CPLEX_Studio201/cplex/include', '-I/opt/ibm/ILOG/CPLEX_Studio201/concert/include', '-L/opt/ibm/ILOG/CPLEX_Studio201/cplex/lib/x86-64_linux/static_pic', '-L/opt/ibm/ILOG/CPLEX_Studio201/concert/lib/x86-64_linux/static_pic', '-lconcert', '-lilocplex', '-lcplex', '-lm', '-lpthread', '-ldl'

This is the code I have added to the wscript file in the src/wifi module folder:
def configure(conf):
    conf.env['ENABLE_cplex'] = conf.check(mandatory=True,
    libpath=['/opt/ibm/ILOG/CPLEX_Studio201/cplex/lib/x86-64_linux/static_pic'],
    includes=['/opt/ibm/ILOG/CPLEX_Studio201/cplex/include'],
    linkflags=['-lilocplex', '-lcplex'],
    ldflags=['-lm', '-lpthread', '-ldl'],
    lib='cplex',
    uselib_store='LIB_CPLEX')

    conf.env['ENABLE_concert'] = conf.check(mandatory=True,
    libpath=['/opt/ibm/ILOG/CPLEX_Studio201/concert/lib/x86-64_linux/static_pic'],
    includes=['/opt/ibm/ILOG/CPLEX_Studio201/concert/include'],
    linkflags=['-lconcert'],
    ldflags=['-lm', '-lpthread', '-ldl'],
    lib='concert',
    uselib_store='LIB_CONCERT')

def build(bld):
     obj.use.append('LIB_CPLEX')
     obj.use.append('LIB_CONCERT')

I am able to get waf build system find the header files and ./waf configure also reports finding the CPLEX libraries, however when I do a ./waf build, I get an 'undefined reference' error of the form:
/usr/bin/ld: build/lib/libns3-dev-wifi-debug.so undefined reference to 'IloCplexI:getDuals'
/usr/bin/ld: build/lib/libns3-dev-wifi-debug.so undefined reference to 'IloCplexI:getSlacks'
..
..

I tried to run the verbose and all these flags are being applied appropriately when the g++ compiler is being called to compile the .cc file in the wifi module folder that uses the CPLEX library. But it seems that for some reason the shared object libraries cannot be linked to the object file that contains the code using the external CPLEX library.

Any sort of hints would be greatly appreciated.

Thank You
Harshal


Harshal Dev

unread,
Sep 2, 2021, 5:31:32 AM9/2/21
to ns-3-users
One correction, the flags are being applied correctly when compiling the simulation program** I have written in the scratch folder (the simulation program uses the wifi module), the object file for the .cc file in the wifi module that uses the CPLEX library is NOT being created since the build fails.

Tom Henderson

unread,
Sep 2, 2021, 9:30:38 AM9/2/21
to ns-3-...@googlegroups.com, Harshal Dev
On 9/2/21 2:31 AM, Harshal Dev wrote:
> One correction, the flags are being applied correctly when compiling the
> simulation program** I have written in the scratch folder (the
> simulation program uses the wifi module), the object file for the .cc
> file in the wifi module that uses the CPLEX library is NOT being created
> since the build fails.

Can you check that the compilation commands (via ./waf build -vvv) of
the wifi .cc library file is correct (or not), and compared to the flags
that are applied to the scratch .cc program?

Have you tried appending the CPLEX library location to the
LD_LIBRARY_PATH environment variable?

- Tom

Veerendra Kumar Gautam

unread,
Dec 11, 2022, 9:56:39 AM12/11/22
to ns-3-users
## -*- 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:00:25 AM12/11/22
to ns-3-users
My question is now Ns-3 has changed to cmake build system. So how to link cplex with cmake build system? . If anyone is able to do that please let me know.
Thank you

Gabriel Ferreira

unread,
Dec 11, 2022, 10:17:27 AM12/11/22
to ns-3-users
The reliable and cross-platform way is finding a FindCPLEX.cmake (e.g. https://github.com/ampl/mp/blob/master/support/cmake/FindCPLEX.cmake

Copying it to build-support/3rd-party, then calling

find_package(CPLEX)

Then add one or more of the libraries (cplex-library,  cplex-concert,  ilocplex, cplex-cp) 
to the LIBRARIES_TO_LINK list of the targets that you want to link them. 

Veerendra Kumar Gautam

unread,
Dec 11, 2022, 10:23:06 AM12/11/22
to ns-3-...@googlegroups.com
Thank you 

Gabriel Ferreira




--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to a topic in the Google Groups "ns-3-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ns-3-users/GVsE1z4PgHU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/e1e8e887-aa40-4e79-ba5e-f6c4ae2383adn%40googlegroups.com.


--
Thanks and Regards,
Veerendra Kumar Gautam
Ph.D. Research Scholar
Dept. of Computer Science and Engineering
Indian Institute of Technology Hyderabad

Disclaimer:- This footer text is to convey that this email is sent by one of the users of IITH. So, do not mark it as SPAM.

Veerendra Kumar Gautam

unread,
Dec 14, 2022, 8:17:20 AM12/14/22
to ns-3-...@googlegroups.com
Four files has to be change in the following dir:
/
/build-support
/build-support
build-support/3rd-party
cplex_cmake_files.zip
Reply all
Reply to author
Forward
0 new messages