Can't find a way to work opencv library with ns3

288 views
Skip to first unread message

iamob...@gmail.com

unread,
Mar 24, 2014, 3:55:35 PM3/24/14
to ns-3-...@googlegroups.com
Hello all,

i want to ask about a problem that i faced in using ns3 and can't find any clue to solve it. so if any one can help I'd really appreciate it.

since there is no enough and sufficient information about linking ns3 with external libraries in:
http://www.nsnam.org/wiki/index.php/HOWTO_use_ns-3_with_other_libraries
and that in turn give you link to this to:
http://shieldroute.blogspot.se/2012/08/extending-ns3-with-your-module-and.html

read those and more and more in this group and elsewhere but still can't help me to link openCV library to ns3
know that i compile openCV code in C++ as follows :

g++ source_name.cc -o output_name `pkg-config --cflags --libs opencv`

so basically it's using linking in the compilation code and using pkg-config in this whole thing. and as a result of searching for something that helps i found in:
http://waf.googlecode.com/svn/docs/apidocs/tools/c_config.html

to modify wscrip as follows -where i want to use it- (and to me I'm trying to use it with applications model):

def configure(conf):
   conf.check_cfg(package='opencv', args='--cflags --libs',  uselib_store='OPENCV',mandatory=True)


and add:

def build(bld):
    module = bld.create_ns3_module('
applications', ['internet'.........])
    module.use.append('OPENCV')



till this far and when i run this command
./waf -d debug --enable-examples --enable-tests configure

it gives a checking note as:

checking for 'opencv'
                         : yse

but still when i run this command:  ./waf
i get the errors :

undefined reference to `cvGet2D'
undefined reference to `cvCreateImage'

and those errors are the same as when i compile a code of only openCV with this:

g++ source_name.cc -o output_name              without this part         `pkg-config --cflags --libs opencv`

and what most reviews about those kind of errors
undefined reference to.. says about it that it's an error in linking the openCV library.

Tommaso Pecorella

unread,
Mar 24, 2014, 5:57:45 PM3/24/14
to ns-3-...@googlegroups.com
Hi,

no idea.

Definitely it's a linking error. I.e., the right argument is not passed to the linker.

However, I can spot a difference between your code and the example one.
def configure(conf):
   conf.env['xercersc'] = conf.check(mandatory=True, lib='xerces-c', uselib_store='XERCES')
your
def configure(conf):
   conf
.check_cfg(package='opencv', args='--cflags --libs',  uselib_store='OPENCV',mandatory=True)

These two are different. Radically different...
I'm not a waf expert, but I bet that this is the issue.

I can suggest using "./waf --no-task-lines -v" and see what's exactly the issued linker command. In this way you'll see if waf is using the right "-l" option.

Cheers,

T.

iamob...@gmail.com

unread,
Mar 24, 2014, 7:33:45 PM3/24/14
to ns-3-...@googlegroups.com
the code :

def configure(conf):
   conf.env['xercersc'] = conf.check(mandatory=True, lib='xerces-c', uselib_store='XERCES')
is used when you link  a library with compilation as -Ixercersc or -Lxercersc parameter

but in my case it uses
pkg-config as i mention before. you compile a code with openCV library as :

g++ source_name.cc -o output_name `pkg-config --cflags --libs opencv`


and look how the parameters are passed to the compiler; is total different and as i search for using pkg-config with ns3 and found nothing i search for using pkg-config with waf and found it in link
http://waf.googlecode.com/svn/docs/apidocs/tools/c_config.html

any way i tried
./waf --no-task-lines -v and the output was as follows:

[1937/2112] cxxprogram: build/examples/tcp/tcp-large-transfer.cc.1.o -> build/examples/tcp/ns3.19-tcp-large-transfer-debug
00:58:57 runner ['/usr/bin/g++', '-I/usr/local/include/opencv', '-I/usr/local/include', '-I/usr/local/include/opencv', '-I/usr/local/include', '-pthread', '-pthread', '/usr/local/lib/libopencv_calib3d.so', '/usr/local/lib/libopencv_contrib.so', '/usr/local/lib/libopencv_core.so', '/usr/local/lib/libopencv_features2d.so', '/usr/local/lib/libopencv_flann.so', '/usr/local/lib/libopencv_gpu.so', '/usr/local/lib/libopencv_highgui.so', '/usr/local/lib/libopencv_imgproc.so', '/usr/local/lib/libopencv_legacy.so', '/usr/local/lib/libopencv_ml.so', '/usr/local/lib/libopencv_nonfree.so', '/usr/local/lib/libopencv_objdetect.so', '/usr/local/lib/libopencv_ocl.so', '/usr/local/lib/libopencv_photo.so', '/usr/local/lib/libopencv_stitching.so', '/usr/local/lib/libopencv_superres.so', '/usr/local/lib/libopencv_ts.a', '/usr/local/lib/libopencv_video.so', '/usr/local/lib/libopencv_videostab.so', 'examples/tcp/tcp-large-transfer.cc.1.o', '-o', '/home/islamobaidat/Desktop/ns-allinone-3.19/ns-3.19/build/examples/tcp/ns3.19-tcp-large-transfer-debug', '-Wl,-Bstatic', '-Wl,-Bdynamic', '-Wl,--no-as-needed', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-lns3.19-point-to-point-debug', '-lns3.19-applications-debug', '-lns3.19-internet-debug', '-lns3.19-mpi-debug', '-lns3.19-bridge-debug', '-lns3.19-config-store-debug', '-lns3.19-network-debug', '-lns3.19-stats-debug', '-lns3.19-core-debug', '-lrt', '-lgsl', '-lgslcblas', '-lm', '-lsqlite3', '-lgtk-x11-2.0', '-lgdk-x11-2.0', '-latk-1.0', '-lgio-2.0', '-lpangoft2-1.0', '-lpangocairo-1.0', '-lgdk_pixbuf-2.0', '-lcairo', '-lpango-1.0', '-lfreetype', '-lfontconfig', '-lgobject-2.0', '-lglib-2.0', '-lxml2', '-lrt', '-lpthread', '-lm', '-ldl']
./libns3.19-applications-debug.so: undefined reference to `cvGet2D'
./libns3.19-applications-debug.so: undefined reference to `cvCreateImage'
collect2: ld returned 1 exit status
Waf: Leaving directory `/home/nenen/Desktop/ns-allinone-3.19/ns-3.19/build'
Build failed
 -> task in 'tcp-large-transfer' failed (exit status 1):
    {task 38487248: cxxprogram tcp-large-transfer.cc.1.o -> ns3.19-tcp-large-transfer-debug}
['/usr/bin/g++', '-I/usr/local/include/opencv', '-I/usr/local/include', '-I/usr/local/include/opencv', '-I/usr/local/include', '-pthread', '-pthread', '/usr/local/lib/libopencv_calib3d.so', '/usr/local/lib/libopencv_contrib.so', '/usr/local/lib/libopencv_core.so', '/usr/local/lib/libopencv_features2d.so', '/usr/local/lib/libopencv_flann.so', '/usr/local/lib/libopencv_gpu.so', '/usr/local/lib/libopencv_highgui.so', '/usr/local/lib/libopencv_imgproc.so', '/usr/local/lib/libopencv_legacy.so', '/usr/local/lib/libopencv_ml.so', '/usr/local/lib/libopencv_nonfree.so', '/usr/local/lib/libopencv_objdetect.so', '/usr/local/lib/libopencv_ocl.so', '/usr/local/lib/libopencv_photo.so', '/usr/local/lib/libopencv_stitching.so', '/usr/local/lib/libopencv_superres.so', '/usr/local/lib/libopencv_ts.a', '/usr/local/lib/libopencv_video.so', '/usr/local/lib/libopencv_videostab.so', 'examples/tcp/tcp-large-transfer.cc.1.o', '-o', '/home/islamobaidat/Desktop/ns-allinone-3.19/ns-3.19/build/examples/tcp/ns3.19-tcp-large-transfer-debug', '-Wl,-Bstatic', '-Wl,-Bdynamic', '-Wl,--no-as-needed', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-lns3.19-point-to-point-debug', '-lns3.19-applications-debug', '-lns3.19-internet-debug', '-lns3.19-mpi-debug', '-lns3.19-bridge-debug', '-lns3.19-config-store-debug', '-lns3.19-network-debug', '-lns3.19-stats-debug', '-lns3.19-core-debug', '-lrt', '-lgsl', '-lgslcblas', '-lm', '-lsqlite3', '-lgtk-x11-2.0', '-lgdk-x11-2.0', '-latk-1.0', '-lgio-2.0', '-lpangoft2-1.0', '-lpangocairo-1.0', '-lgdk_pixbuf-2.0', '-lcairo', '-lpango-1.0', '-lfreetype', '-lfontconfig', '-lgobject-2.0', '-lglib-2.0', '-lxml2', '-lrt', '-lpthread', '-lm', '-ldl']

it really shows that the library is called (linked) but it's not able to use it or it's not linked the right way or ...
i don't know it might be a bug in ns3

Tommaso Pecorella

unread,
Mar 25, 2014, 3:52:52 AM3/25/14
to ns-3-...@googlegroups.com
Hi,

the bug isn't in ns-3. It's in how you're calling the linker.

You're correct in saying that you need a module-wide configuration, but when you compile the module you don't need to link the module itself against the OpenCV library.

Unfortunately, I'm not a deep expert in linking, but I can point one difference.
In ns-3 you're building a library. The library is (when needed) linked to one particular script to build an executable.
In your example program, you're using g++ to build an executable (g++ will call the linker directly).

I really think that pkg-config is not the way to mimic stuff. Not in ns-3 case.

Corry if I can't help more.

T.


On Monday, March 24, 2014 8:55:35 PM UTC+1, iamob...@gmail.com wrote:

iamob...@gmail.com

unread,
Mar 25, 2014, 12:25:01 PM3/25/14
to ns-3-...@googlegroups.com
I'll try to search more about this, thank you anyway.

Shady M

unread,
Mar 27, 2014, 1:40:19 PM3/27/14
to ns-3-...@googlegroups.com

Hi there ,

If you managed to solve this problem , i'am kind of stuck in similar problem and could use some help

iamob...@gmail.com

unread,
Mar 29, 2014, 2:32:16 PM3/29/14
to ns-3-...@googlegroups.com
hi, you may read previous info. maybe you're problem is linking libraries as the one in nsnam site
but if you're using pkg-config with the linking; i still can't find a way to that nor get any help,

maitane chaves

unread,
Mar 3, 2015, 12:44:49 PM3/3/15
to ns-3-...@googlegroups.com
Hi,
I have the same problem that you told. And I would like to know if you had solved the problem.
I am trying to use openssl with ns3
Thanks
Reply all
Reply to author
Forward
0 new messages