Linking external libraries using waf

1,286 views
Skip to first unread message

Vijay

unread,
Jun 3, 2009, 3:12:54 PM6/3/09
to ns-3-users
Hello: I am using ns-3.4 and writing a new application model. In that
model, I am using Ted Tso's uuid library. How do I give waf the right
incantations so it links libuuid.so? I tried looking at the archives
but could not find anything of help.

I looked to see if waf supports any command line options to accept
external libraries, but that does not appear to be the case. I also
checked if wscript allows one to put external libraries, but could not
find anything in it either.

Thanks,

- vijay

francesco

unread,
Jun 5, 2009, 6:40:02 AM6/5/09
to ns-3-users
You have to add a line like this to the wscript file of the module/
directory you are adding/editing (say, ns-3-dev/src/applications/myapp/
wscript):

def configure(conf):
conf.check(lib='xml2', uselib='XML2', define_name='HAVE_XML2')
conf.check(lib='pq', uselib='PQ', define_name='HAVE_PQ')

Additionally, if you are creating a new module, you must add a
reference to it in ns-3-dev/src/wscript, like this:

def configure(conf):
conf.sub_config('core')
[...]
conf.sub_config('applications/myapp') # <<-- add this

Vijay Gurbani

unread,
Jun 5, 2009, 12:28:10 PM6/5/09
to ns-3-users
On Jun 5, 5:40 am, francesco <francesco.malandr...@gmail.com> wrote:
> You have to add a line like this to the wscript file of the module/
> directory you are adding/editing (say, ns-3-dev/src/applications/myapp/
> wscript):
[...]

Francesco: Thank you for your reply. I did as you suggested. But
something is still missing.

To wit:
1) I added a link in applications/myapp/wscript as follows:
conf.check(lib='uuid', uselib='UUID', define_name='UUID')

On running waf in applications/myapp, it detected that the
reconfiguration had changed. It reconfigured and reported that 'uuid'
was found:

Checking for library uuid : ok

2) In src/wscript, I added the conf.sub_config(...) as you suggested.

Now, when I run "./waf --run scratch/first", it is still unable to
link to libuuid.so:

./waf --run scratch/first
Entering directory `/home/vijay/sim/ns-allinone-3.4/ns-3.4/build'
[267/267] cxx_link: build/debug/scratch/first_4.o -> build/debug/
scratch/first
debug/libns3.so: undefined reference to `uuid_generate'
collect2: ld returned 1 exit status
Build failed
-> task failed (err #1):
{task: cxx_link first_4.o -> first}

To see which libraries it is linking, I tried "./waf --verbose --run
scratch/first", and not surprisingly, -luuid is not in the link list:

$ ./waf --verbose --run scratch/first
Entering directory `/home/vijay/sim/ns-allinone-3.4/ns-3.4/build'
[267/267] cxx_link: build/debug/scratch/first_4.o -> build/debug/
scratch/first
12:26:25 runner system command -> /usr/lib64/ccache/g++ debug/scratch/
first_4.o -o debug/scratch/first -pthread -Ldebug -Wl,-Bdynamic -lns3 -
lsqlite3 -ldl -lxml2 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -
lgdk_pixbuf-2.0 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -
lgmodule-2.0 -lglib-2.0 -lrt
debug/libns3.so: undefined reference to `uuid_generate'
collect2: ld returned 1 exit status
Build failed
-> task failed (err #1):
{task: cxx_link first_4.o -> first}
File "./waf", line 127, in <module>
[...]

So, there is still some more magic to be done, but I am not sure
where...

Thanks,

- vijay


Gustavo Carneiro

unread,
Jun 5, 2009, 1:23:35 PM6/5/09
to ns-3-...@googlegroups.com
2009/6/5 Vijay Gurbani <vijay....@gmail.com>

I guess you could link with -luuid globally.  See below:


diff -r 443df3250809 wscript
--- a/wscript    Thu Jun 04 12:07:48 2009 -0700
+++ b/wscript    Fri Jun 05 18:19:56 2009 +0100
@@ -495,6 +495,8 @@
         lib.target = 'ns3'
         if lib.env['CXX_NAME'] == 'gcc' and env['WL_SONAME_SUPPORTED']:
             lib.env.append_value('LINKFLAGS', '-Wl,--soname=%s' % ccroot.get_target_name(lib))
+    lib.env.append_value('LIB', 'uuid')
+
 
     if env['NS3_ENABLED_MODULES']:
         lib.add_objects = list(modules)
 


Thanks,

- vijay







--
Gustavo J. A. M. Carneiro
INESC Porto, Telecommunications and Multimedia Unit
"The universe is always one step beyond logic." -- Frank Herbert
Reply all
Reply to author
Forward
0 new messages