External library in non-standard path (in ns-3 'src' dir)

1,179 views
Skip to first unread message

Chris Facchini

unread,
Jul 7, 2010, 12:44:26 PM7/7/10
to ns-3-users
Hi,

I am trying to include in ns-3 an external library (libDAI).
I have already read some threads about it [1-3], still I am
experiencing some difficulties.

The library I am trying to include is in a non-standard path: more
specifically it is placed in src/contrib/myapp/libdai. (The reason is
that I want it to be shipped along with the ns-3 code.)
The library itself (libdai.a) resides in src/contrib/myapp/libdai/lib.

So far, I have managed to have my source codes see the header files of
the lib (which, as a side effect, now have to be included like this:
"#include <ns3/libraryheader.h>).
However, the program is not linked against the library itself (ld
reports undefined references).

This is what I put in src/contrib/myapp/wscript (basically, the
approach suggested in [1]):
def build(bld):
obj = bld.create_ns3_module('myapp', ['core', 'simulator'])
obj.env.append_value('LIBPATH', ['libdai/lib'])
obj.env.append_value('LIB', ['dai'])
obj.source = [
# list of .cc files belonging to 'myapp'
]
headers = bld.new_task_gen('ns3header')
headers.module = 'cogent'
headers.source = [
# list of .h files including both those belonging to 'myapp' and those
belonging to the library
]
obj.includes = 'libdai/include'

I'm running out of clues. Any suggestion?
TIA,
Chris


[1] http://groups.google.com/group/ns-3-users/browse_frm/thread/5352de44e36715c/55e2c5c28b0216f4
[2] http://groups.google.com/group/ns-3-users/browse_frm/thread/94d9b6ccbf47884f/5a76aa7151e9d00f
[3] http://groups.google.com/group/ns-3-users/browse_frm/thread/cd2062d3095e0e0a/1ab8346c161f8d73

Gustavo Carneiro

unread,
Jul 7, 2010, 1:18:49 PM7/7/10
to ns-3-...@googlegroups.com
On Wed, Jul 7, 2010 at 17:44, Chris Facchini <c.fac...@gmail.com> wrote:
Hi,

I am trying to include in ns-3 an external library (libDAI).
I have already read some threads about it [1-3], still I am
experiencing some difficulties.

The library I am trying to include is in a non-standard path: more
specifically it is placed in src/contrib/myapp/libdai. (The reason is
that I want it to be shipped along with the ns-3 code.)
The library itself (libdai.a) resides in src/contrib/myapp/libdai/lib.

So far, I have managed to have my source codes see the header files of
the lib (which, as a side effect, now have to be included like this:
"#include <ns3/libraryheader.h>).
However, the program is not linked against the library itself (ld
reports undefined references).

This is what I put in src/contrib/myapp/wscript (basically, the
approach suggested in [1]):
def build(bld):
   obj = bld.create_ns3_module('myapp', ['core', 'simulator'])
   obj.env.append_value('LIBPATH', ['libdai/lib'])

When building, waf runs with CWD equal to the root build dir, in case of ns-3 'build'.  Additionally, I don't think waf will process LIBPATH and convert the path; I suspect it will just pass this path as it is into the linker.  If my theory is correct, you should pass the option:

     obj.env.append_value('LIBPATH', ['../src/contrib/myapp/libdai/lib'])

Furthermore, build with ./waf -v, to see what system commands waf is using and what -L options it is using the link stage, to check if your options are being passed along.
 
   obj.env.append_value('LIB', ['dai'])
   obj.source = [
# list of .cc files belonging to 'myapp'
       ]
   headers = bld.new_task_gen('ns3header')
   headers.module = 'cogent'
   headers.source = [
# list of .h files including both those belonging to 'myapp' and those
belonging to the library
       ]
   obj.includes = 'libdai/include'

I'm running out of clues. Any suggestion?
TIA,
Chris


[1] http://groups.google.com/group/ns-3-users/browse_frm/thread/5352de44e36715c/55e2c5c28b0216f4
[2] http://groups.google.com/group/ns-3-users/browse_frm/thread/94d9b6ccbf47884f/5a76aa7151e9d00f
[3] http://groups.google.com/group/ns-3-users/browse_frm/thread/cd2062d3095e0e0a/1ab8346c161f8d73

--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.




--
Gustavo J. A. M. Carneiro
INESC Porto, UTM, WiN, http://win.inescporto.pt/gjc
"The universe is always one step beyond logic." -- Frank Herbert

Lalith Suresh

unread,
Jul 8, 2010, 8:46:20 AM7/8/10
to ns-3-...@googlegroups.com

Chris Facchini

unread,
Jul 12, 2010, 4:22:17 AM7/12/10
to ns-3-users
First of all, thank you both for helping me out.
I was really stuck here.

After almost half a week of pain I managed to solve the problem
(somehow), however the solution is very inelegant (mainly because the
waf building system is overly complex to me and I do not have much
time to learn it).

On Jul 7, 7:18 pm, Gustavo Carneiro wrote:
> When building, waf runs with CWD equal to the root build dir, in case of
> ns-3 'build'.  Additionally, I don't think waf will process LIBPATH and
> convert the path; I suspect it will just pass this path as it is into the
> linker.  If my theory is correct, you should pass the option:
>
>      obj.env.append_value('LIBPATH', ['../src/contrib/myapp/libdai/lib'])
>
> Furthermore, build with ./waf -v, to see what system commands waf is using
> and what -L options it is using the link stage, to check if your options are
> being passed along.

By turning on verbosity, not only did I discover that waf does not
convert the paths but also, and more importantly, that LIB and LIBPATH
go completely ignored!
Here's an example of what I get:
[ 556/1194] cxx: src/contrib/myapp/cognitive-entity.cc -> build/debug/
src/contrib/myapp/cognitive-entity_1.o
09:49:03 runner system command -> ['/usr/bin/g++', '-O0', '-ggdb', '-
g3', '-Wall', '-Werror', '-Wno-error=deprecated-declarations', '-
fPIC', '-DPIC', '-Idebug', '-I..', '-Isrc/contrib/myapp', '-D_DEBUG',
'-DNS3_ASSERT_ENABLE', '-DNS3_LOG_ENABLE', '-DENABLE_GSL', '-
DNS3_MODULE_COMPILATION', '../src/contrib/myapp/cognitive-entity.cc',
'-c', '-o', 'debug/src/contrib/myapp/cognitive-entity_1.o']

Curiously, CPPPATH *is* processed: in the example above I specified
obj.env.append_value('CPPPATH', ['src/contrib/myapp']) which in fact
appears in the command.
The problem then is when waf starts building a script in the scratch
directory that includes a header file in the 'myapp' dir that, in
turn, includes a header file of the library: CPPPATH does not include
the path defined above and the source does not compile.

On Jul 8, 2:46 pm, Lalith Suresh wrote:
> Have a look at http://code.nsnam.org/lalith/ns-3-click/file/5b999177bf08/src/routing...
>
> The library is linked from a non-standard path specified by the user.

Thanks for pointing me to this example.
I tailored it to fit my needs, and now, more or less, it is working.

To make it work, I had to:
- install the library in a standard place (/usr/local/lib was my
choice)
- add the 'include' and 'lib' path *globally*, that is, like this:
def configure(conf)
...
conf.env['CPPPATH_LIBDAI'] =
[os.path.abspath(os.path.join(conf.env['WITH_LIBDAI'],'include'))]
conf.env['LIBPATH_LIBDAI'] =
[os.path.abspath(os.path.join(conf.env['WITH_LIBDAI'],'lib'))]
conf.env.append_value('CPPPATH', conf.env['CPPPATH_LIBDAI'])
conf.env.append_value('LIBPATH', conf.env['LIBPATH_LIBDAI'])
- link the library in 'create_ns3_program' (awful, but the only way
I could make it work)
def create_ns3_program(bld, name, dependencies=('simulator',)):
...
program.env.append_value('LINKFLAGS', '-ldai')

If I manage to find a clever solution, I'll post it here.
Chris

ns3...@gmail.com

unread,
Aug 23, 2013, 3:41:19 PM8/23/13
to ns-3-...@googlegroups.com
Hi all,
I am new to ns3 and I have checked and implemented the examples present in ns3. 

I have to implement a project for which i have created a QT dynamic library using IDE netbeans.I have read the help present in this forum (especially answers of Gustavo Carneiro and Tom Henderson,those were really helpful) and the ns3 nsnam website. What i figured out is that I need to create a module.so I created the module by executing the create-module.py which create some templates and wscript file.Now in order to link the library i need to modify wscript.py file.

To link the library i made following changes in the wscript.py file

        bld.env.append_value("LINKFLAGS", ["-L/home/a/NetBeansProjects/QDynLib/dist/Debug/GNU-Linux-x86"])
        bld.env.append_value("LIB", ["libQDynLib"])

but still building is not successful and i am getting the following errors(complete build error is attached):
.
.
.
[1706/1995] cxx: examples/udp-client-server/udp-trace-client-server.cc -> build/examples/udp-client-server/udp-trace-client-server.cc.2.o
[1707/1995] cxxshlib: build/src/core/model/time.cc.1.o build/src/core/model/event-id.cc.1.o build/src/core/model/scheduler.cc.1.o build/src/core/model/list-scheduler.cc.1.o build/src/core/model/map-scheduler.cc.1.o build/src/core/model/heap-scheduler.cc.1.o build/src/core/model/calendar-scheduler.cc.1.o build/src/core/model/event-impl.cc.1.o build/src/core/model/simulator.cc.1.o build/src/core/model/simulator-impl.cc.1.o build/src/core/model/default-simulator-impl.cc.1.o build/src/core/model/timer.cc.1.o build/src/core/model/watchdog.cc.1.o build/src/core/model/synchronizer.cc.1.o build/src/core/model/make-event.cc.1.o build/src/core/model/log.cc.1.o build/src/core/model/breakpoint.cc.1.o build/src/core/model/type-id.cc.1.o build/src/core/model/attribute-construction-list.cc.1.o build/src/core/model/object-base.cc.1.o build/src/core/model/ref-count-base.cc.1.o build/src/core/model/object.cc.1.o build/src/core/model/test.cc.1.o build/src/core/model/random-variable.cc.1.o build/src/core/model/random-variable-stream.cc.1.o build/src/core/model/rng-seed-manager.cc.1.o build/src/core/model/rng-stream.cc.1.o build/src/core/model/command-line.cc.1.o build/src/core/model/type-name.cc.1.o build/src/core/model/attribute.cc.1.o build/src/core/model/boolean.cc.1.o build/src/core/model/integer.cc.1.o build/src/core/model/uinteger.cc.1.o build/src/core/model/enum.cc.1.o build/src/core/model/double.cc.1.o build/src/core/model/int64x64.cc.1.o build/src/core/model/string.cc.1.o build/src/core/model/pointer.cc.1.o build/src/core/model/object-ptr-container.cc.1.o build/src/core/model/object-factory.cc.1.o build/src/core/model/global-value.cc.1.o build/src/core/model/trace-source-accessor.cc.1.o build/src/core/model/config.cc.1.o build/src/core/model/callback.cc.1.o build/src/core/model/names.cc.1.o build/src/core/model/vector.cc.1.o build/src/core/model/fatal-impl.cc.1.o build/src/core/model/system-path.cc.1.o build/src/core/model/unix-system-wall-clock-ms.cc.1.o build/src/core/model/int64x64-128.cc.1.o build/src/core/model/realtime-simulator-impl.cc.1.o build/src/core/model/wall-clock-synchronizer.cc.1.o build/src/core/model/system-thread.cc.1.o build/src/core/model/unix-fd-reader.cc.1.o build/src/core/model/unix-system-mutex.cc.1.o build/src/core/model/unix-system-condition.cc.1.o -> build/libns3.16-core-debug.so
/usr/bin/ld: cannot find -llibQDynLib
collect2: ld returned 1 exit status
Waf: Leaving directory `/home/a/Documents/ns-allinone-3.16/ns-3.16/build'
Build failed
 -> task in 'ns3-core' failed (exit status 1): 
{task 43849872: cxxshlib time.cc.1.o,event-id.cc.1.o,scheduler.cc.1.o,list-scheduler.cc.1.o,map-scheduler.cc.1.o,heap-scheduler.cc.1.o,calendar-scheduler.cc.1.o,event-impl.cc.1.o,simulator.cc.1.o,simulator-impl.cc.1.o,default-simulator-impl.cc.1.o,timer.cc.1.o,watchdog.cc.1.o,synchronizer.cc.1.o,make-event.cc.1.o,log.cc.1.o,breakpoint.cc.1.o,type-id.cc.1.o,attribute-construction-list.cc.1.o,object-base.cc.1.o,ref-count-base.cc.1.o,object.cc.1.o,test.cc.1.o,random-variable.cc.1.o,random-variable-stream.cc.1.o,rng-seed-manager.cc.1.o,rng-stream.cc.1.o,command-line.cc.1.o,type-name.cc.1.o,attribute.cc.1.o,boolean.cc.1.o,integer.cc.1.o,uinteger.cc.1.o,enum.cc.1.o,double.cc.1.o,int64x64.cc.1.o,string.cc.1.o,pointer.cc.1.o,object-ptr-container.cc.1.o,object-factory.cc.1.o,global-value.cc.1.o,trace-source-accessor.cc.1.o,config.cc.1.o,callback.cc.1.o,names.cc.1.o,vector.cc.1.o,fatal-impl.cc.1.o,system-path.cc.1.o,unix-system-wall-clock-ms.cc.1.o,int64x64-128.cc.1.o,realtime-simulator-impl.cc.1.o,wall-clock-synchronizer.cc.1.o,system-thread.cc.1.o,unix-fd-reader.cc.1.o,unix-system-mutex.cc.1.o,unix-system-condition.cc.1.o -> libns3.16-core-debug.so}
['/usr/bin/g++', '-Wl,--soname=libns3.16-core-debug.so', '-shared', '-pthread', 'src/core/model/time.cc.1.o', 'src/core/model/event-id.cc.1.o', 'src/core/model/scheduler.cc.1.o', 'src/core/model/list-scheduler.cc.1.o', 'src/core/model/map-scheduler.cc.1.o', 'src/core/model/heap-scheduler.cc.1.o', 'src/core/model/calendar-scheduler.cc.1.o', 'src/core/model/event-impl.cc.1.o', 'src/core/model/simulator.cc.1.o', 'src/core/model/simulator-impl.cc.1.o', 'src/core/model/default-simulator-impl.cc.1.o', 'src/core/model/timer.cc.1.o', 'src/core/model/watchdog.cc.1.o', 'src/core/model/synchronizer.cc.1.o', 'src/core/model/make-event.cc.1.o', 'src/core/model/log.cc.1.o', 'src/core/model/breakpoint.cc.1.o', 'src/core/model/type-id.cc.1.o', 'src/core/model/attribute-construction-list.cc.1.o', 'src/core/model/object-base.cc.1.o', 'src/core/model/ref-count-base.cc.1.o', 'src/core/model/object.cc.1.o', 'src/core/model/test.cc.1.o', 'src/core/model/random-variable.cc.1.o', 'src/core/model/random-variable-stream.cc.1.o', 'src/core/model/rng-seed-manager.cc.1.o', 'src/core/model/rng-stream.cc.1.o', 'src/core/model/command-line.cc.1.o', 'src/core/model/type-name.cc.1.o', 'src/core/model/attribute.cc.1.o', 'src/core/model/boolean.cc.1.o', 'src/core/model/integer.cc.1.o', 'src/core/model/uinteger.cc.1.o', 'src/core/model/enum.cc.1.o', 'src/core/model/double.cc.1.o', 'src/core/model/int64x64.cc.1.o', 'src/core/model/string.cc.1.o', 'src/core/model/pointer.cc.1.o', 'src/core/model/object-ptr-container.cc.1.o', 'src/core/model/object-factory.cc.1.o', 'src/core/model/global-value.cc.1.o', 'src/core/model/trace-source-accessor.cc.1.o', 'src/core/model/config.cc.1.o', 'src/core/model/callback.cc.1.o', 'src/core/model/names.cc.1.o', 'src/core/model/vector.cc.1.o', 'src/core/model/fatal-impl.cc.1.o', 'src/core/model/system-path.cc.1.o', 'src/core/model/unix-system-wall-clock-ms.cc.1.o', 'src/core/model/int64x64-128.cc.1.o', 'src/core/model/realtime-simulator-impl.cc.1.o', 'src/core/model/wall-clock-synchronizer.cc.1.o', 'src/core/model/system-thread.cc.1.o', 'src/core/model/unix-fd-reader.cc.1.o', 'src/core/model/unix-system-mutex.cc.1.o', 'src/core/model/unix-system-condition.cc.1.o', '-o', '/home/a/Documents/ns-allinone-3.16/ns-3.16/build/libns3.16-core-debug.so', '-Wl,-Bstatic', '-Wl,-Bdynamic', '-llibQDynLib', '-lrt', '-lgsl', '-lgslcblas', '-lm']
make: *** [all] Error 1


BUILD FAILED (exit value 2, total time: 2m 55s)


can anybody help me please?thanks in advance for help

location of the dynamic library:
home/a/NetBeansProjects/QDynLib/dist/Debug/GNU-Linux-x86
name of library file:libQDynLib
ns3 build error detail.rtf

ns3...@gmail.com

unread,
Aug 27, 2013, 10:13:09 PM8/27/13
to ns-3-...@googlegroups.com

I have resolved that issue after spending some time.I am providing the solution so that it can be helpful to save time:


In order to integrate ns3 and Qt, I;

1)-created the dynamic library of the code written in Qt using IDE netbeans.

2)-In order to link and use that library I place the header file in the build/project folder so that I can use it easily.After that to link the dynamic library in ns3, I added following lines in the script file:


module.ccflags=['-wall','-O3'] 

module.lib=['QDynLib'] 

module.libpath=['/home/a/Documents/ns-allinone-3.16/ns-3.16/src/propagation/QDynLib/dist/Debug/GNU-Linux-x86'] 

module.linkflag=['-g'] #module.install_path=['/home/a/Documents/ns-allinone-3.16/ns-3.16/src/propagation/QDynLib/dist/Debug/GNU-Linux-x86']

module.rpath=['/home/a/Documents/ns-allinone-3.16/ns-3.16/src/propagation/QDynLib/dist/Debug/GNU-Linux-x86']


Here,I used the absolute path to locate the dynamic library.


Location of the Dynamic library;

/home/a/Documents/ns-allinone-3.16/ns-3.16/src/propagation/QDynLib/dist/Debug/GNU-Linux-x86/

Name of the library File:

libQDynLib.so


to find the explanation and detail of these command please refer to the link:

http://docs.waf.googlecode.com/git/book_15/single.html#_c_and_c_projects




Reply all
Reply to author
Forward
0 new messages