Link a library?

9 views
Skip to first unread message

francesco

unread,
Nov 6, 2008, 4:53:15 PM11/6/08
to ns-3-users
Hi,

I have developed a module that uses GNOME's libxml2 features.
How do I tell waf that ns3 binaries are to be linked against it? I.e.,
how do I append a "-lxml2" option to the linker command line?

Thanks,

Francesco

francesco

unread,
Nov 7, 2008, 3:40:50 AM11/7/08
to ns-3-users
Ok, this is how I worked it out:

1) add a "def configure(conf):" part to your module's wscript:

def configure(conf):
lib = conf.create_library_configurator()
lib.mandatory = False
lib.name = 'xml2'
lib.define = 'XML2'
lib.uselib = 'XML2'
haxXml2 = lib.run()

2) make sure your module's directory is listed inside src/wscript "def
configure(conf):" section:

def configure(conf):
conf.sub_config('core')
conf.sub_config('process-manager')
conf.sub_config('simulator')
conf.sub_config('contrib')
conf.sub_config('internet-stack')
conf.sub_config('applications/arigtt-agent') ## add this!

Gustavo Carneiro

unread,
Nov 7, 2008, 5:15:10 AM11/7/08
to ns-3-...@googlegroups.com


2008/11/7 francesco <francesco....@gmail.com>

I think you missed out the part where you make your module.  You have:

     obj = bld.create_ns3_module('my-module', ['dep'])

I think you need to tell your module to use libxml2 via:

    obj.uselib = 'XML2'

Anyway, glad you could figure it out by yourself :-)

--
Gustavo J. A. M. Carneiro
INESC Porto, Telecommunications and Multimedia Unit
"The universe is always one step beyond logic." -- Frank Herbert

francesco

unread,
Nov 7, 2008, 4:42:18 PM11/7/08
to ns-3-users
No, I just forgotten to report it.
However, this is the full wscript of my module:
def configure(conf):
lib = conf.create_library_configurator()
lib.mandatory = False
lib.name = 'xml2'
lib.define = 'XML2'
lib.uselib = 'XML2'
haxXml2 = lib.run()

if not haxXml2:
message = 'library xml2 not installed'
conf.env['XML2'] = False
else:
message = 'ok'
conf.env['XML2'] = True

conf.report_optional_feature("libxml2", "arigtt-agent, needing
libxml2",
conf.env['XML2'],
message)

def build(bld):
module = bld.create_ns3_module('arigtt-agent', ['internet-stack'])
if bld.env()['XML2']:
module.source = [
'arigtt-packets.cc',
'arigtt-agent.cc',
'arigtt-directory.cc',
]
module.uselib = 'XML2'
headers = bld.create_obj('ns3header')
headers.module = 'arigtt-agent'
headers.source = [
'arigtt-agent.h',
'arigtt-packets.h',
'arigtt-directory.h',
]

(by the way, is there a more elegant way that putting the whole thing
into an "if" to tell waf not even to try to compile the module if a
certain library is not available?)
Reply all
Reply to author
Forward
0 new messages