Linking shared libraries in waf

1,244 views
Skip to first unread message

Tiago Cerqueira

unread,
Jul 17, 2014, 12:38:25 PM7/17/14
to ns-3-...@googlegroups.com
Hi,
I'm having problems linking shared libraries in ns3. I'm extending the mobility module with some functionalities and I require 2 libraries (GeographicLib and xercesc). xercesc is identified by pkg-config, but GeographicLib isn't. At the moment, GeographicLib is placed in /usr/local/lib, with the include files placed in /usr/local/include/GeographicLib.
I tried to link these libraries (for now, I'm just trying to link the GeographicLib) but so far, I had no luck. I managed to tell the configure function to look for the library, but the library is never found.
I'm looking for information on how to do this. Everything I find on the web (which isn't much) is not working or doesn't relate to my specific case. Can anyone point me to a link on how to do this? Or give me a brief explanation?
At the moment, I'm unable to post what I have done so far in the wscript of the module, but I'll have access to the file soon enough (10/20m at the most) and I'll post it then.

Thanks!

Tiago Cerqueira

unread,
Jul 17, 2014, 12:53:20 PM7/17/14
to ns-3-...@googlegroups.com
I have made the following changes to the wscript under src/mobility.
def configure(conf):
#conf.env['libGeographic'] = conf.check(mandatory=True,lib='/usr/local/lib/libGeographic.a',libPath='/usr/local/include/GeographicLib', uselib_store='LIB')
conf.check_cxx(lib='libGeographic',
cxxflags='-I /usr/local/include/GeographicLib',
linkflags='-L /usr/local/lib/',
uselib_store='LIB',define_name='HAVE_LIB', mandatory=True)

def build(bld):
    mobility = bld.create_ns3_module('mobility', ['network'])
    mobility.uselib('LIB')
    mobility.source = [...]
    mobility.env.append_value("CXXFLAGS", "-I/usr/local/include/GeographicLib")
    mobility.env.append_value("LINKFLAGS", ["-L/usr/local/lib/"])
    mobility.env.append_value("LIB", ["Geocentric"])

Can anyone help me?

Tom Henderson

unread,
Jul 17, 2014, 4:32:12 PM7/17/14
to Tiago Cerqueira, ns-3-...@googlegroups.com
I don't know what the problem is: I'd have to test it some to learn more.

I'm guessing that you reviewed this bug already:
https://www.nsnam.org/bugzilla/show_bug.cgi?id=1490

We ought to use this as motivation to close out bug 1490 (provide
documentation in this regard). I just added this to the ns-3.21 wiki
page as a documentation goal.

- Tom

Tiago Cerqueira

unread,
Jul 17, 2014, 5:35:20 PM7/17/14
to ns-3-...@googlegroups.com, 109...@isep.ipp.pt
I didn't find that bug, but I found the wiki page and the link to Laurynas Riliskis's blog. I tried both what you mentioned in the comments and the information on the blog, however, nothing worked.
Is there an option I can use to troubleshoot my problem?
My wscript is as follows:

def configure(conf):
        conf.env['LINKFLAGS_GEOLIB'] = '-lGeographicLib' #I tried variations, such as /usr/local/lib, /usr/local/lib/libGeographic.a, /usr/local/lib/libGeographic.so, /usr/local/lib/libGeographic and none worked

def build(bld):
    mobility = bld.create_ns3_module('mobility', ['network'])
    mobility.use.append('GEOLIB')
    mobility.source = [...]
The output of ./waf build is as follows: 
/usr/lib/gcc/i586-suse-linux/4.8/../../../../i586-suse-linux/bin/ld: cannot find -lGeographicLib

Thanks!

Tiago Cerqueira

unread,
Jul 18, 2014, 8:38:07 PM7/18/14
to ns-3-...@googlegroups.com, 109...@isep.ipp.pt
With a huge help from Scott Carpenter, I managed to solve this.
I added the following to my wscript
def configure(conf):
        conf.env.append_value("LINKFLAGS", ["-LGeographic","-L/usr/local/lib/libGeographic.a"])
        conf.env.append_value("LIB", ["Geographic"])

It now compiles with no errors or warnings, and I checked that the sources that used the static library where being compiled.
Scott gave me a brief explanation on what should be added to wscript to link a static library. He mentioned that he was no expert on adding static libraries to ns3, but this worked for me.
Scott Carpenter wrote:
 The main thing to look at is the "def configure(conf)" function.
1.  Adding CXXFLAGS.  This is a compiler switch. 
2. Adding link flags.  This adding the explicit paths so that the linker
knows where to find the static libraries.
 In my case (OP) , /usr/local/lib and the GeographicLib
3. Adding the libs needed.  This is the list of the static libs that need
to be linked in.  
 In this case, my program depends on the Geographic library.
In summary, add CXX flags if necessary, add to LINKFLAGS the paths to find
the libs, and add to LIB the names of the libraries that you are dependent
upon. 

Thanks 

shruti divakar

unread,
Aug 11, 2019, 1:23:29 AM8/11/19
to ns-3-users
Hi Tiago,

i am also trying to enhance the vlc module in ns3 for which i am trying to make use of the fftw3 library. Unfortunately i have not been able to link it successfully with the method given here. Do you have any additional solution which i can try. i get the following error:
./libns3.25-vlc-debug.so: undefined reference to `itpp::ifft_real(itpp::Vec<std::complex<double> > const&, itpp::Vec<double>&)  when i try to build using the "sudo ./waf build command". Can anybody please tell me how to link fftw3 library to ns3 successfully and execute programs having the fft functions. would be of of of help.

Regards,
shruti divakar

Tiago Cerqueira

unread,
Nov 4, 2019, 4:24:08 PM11/4/19
to ns-3-...@googlegroups.com
Hi,

I haven't used ns-3 since 2016 so I can't be of much help to you.

The linking methods I mentioned on the wiki should work. If they don't, something has changed, and I have no idea what.



--
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/dEx5YSLliMQ/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/7db9e95e-3a8a-45c7-876e-2fdaa71bc746%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages