Linking ZMQ to a c++ program in my scratch folder

774 views
Skip to first unread message

Vishnu Raj

unread,
Sep 2, 2018, 7:01:03 AM9/2/18
to ns-3-users
I have a ns3 program under scratch/sample/sample.cc which depends on ZMQ. When I try to run the program, I get this error

scratch/sample/sample.cc.6.o: In function `main':
/media/vish/Y/vish/bits/ns3/source/ns-3.28/build/../scratch/sample/sample.cc:54: undefined reference to `
zmq_ctx_new'
/media/vish/Y/vish/bits/ns3/source/ns-3.28/build/../scratch/sample/sample.cc:55: undefined reference to `zmq_socket'

/media/vish/Y/vish/bits/ns3/source/ns-3.28/build/../scratch/sample/sample.cc:56: undefined reference to `zmq_connect'
collect2: error: ld returned 1 exit status

Waf: Leaving directory `
/media/vish/Y/vish/bits/ns3/source/ns-3.28/build'
Build failed
 -> task in '
sample' failed (exit status 1):
    {task 140042867840272: cxxprogram sample.cc.6.o -> sample}
['
/usr/bin/g++', '-lzmq', '-pthread', '-pthread', 'scratch/sample/sample.cc.6.o', '-o', '/media/vish/Y/vish/bits/ns3/source/ns-3.28/build/scratch/sample/sample', '-Wl,-Bstatic', '-Wl,-Bdynamic', '-Wl,--no-as-needed', '-L.', '-lns3.28-aodv-debug', '-lns3.28-test-debug', '-lns3.28-dsr-debug', '-lns3.28-mesh-debug', '-lns3.28-netanim-debug', '-lns3.28-wave-debug', '-lns3.28-wifi-debug', '-lns3.28-lr-wpan-debug', '-lns3.28-lte-debug', '-lns3.28-spectrum-debug', '-lns3.28-antenna-debug', '-lns3.28-applications-debug', '-lns3.28-csma-layout-debug', '-lns3.28-dsdv-debug', '-lns3.28-flow-monitor-debug', '-lns3.28-internet-apps-debug', '-lns3.28-wimax-debug', '-lns3.28-point-to-point-layout-debug', '-lns3.28-nix-vector-routing-debug', '-lns3.28-olsr-debug', '-lns3.28-sixlowpan-debug', '-lns3.28-tap-bridge-debug', '-lns3.28-internet-debug', '-lns3.28-bridge-debug', '-lns3.28-point-to-point-debug', '-lns3.28-mpi-debug', '-lns3.28-traffic-control-debug', '-lns3.28-buildings-debug', '-lns3.28-propagation-debug', '-lns3.28-uan-debug', '-lns3.28-mobility-debug', '-lns3.28-energy-debug', '-lns3.28-config-store-debug', '-lns3.28-csma-debug', '-lns3.28-fd-net-device-debug', '-lns3.28-virtual-net-device-debug', '-lns3.28-topology-read-debug', '-lns3.28-network-debug', '-lns3.28-stats-debug', '-lns3.28-core-debug', '-lrt', '-lgsl', '-lgslcblas', '-lm', '-lsqlite3', '-lgtk-x11-2.0', '-lgdk-x11-2.0', '-lpangocairo-1.0', '-latk-1.0', '-lcairo', '-lgdk_pixbuf-2.0', '-lgio-2.0', '-lpangoft2-1.0', '-lpango-1.0', '-lgobject-2.0', '-lglib-2.0', '-lfontconfig', '-lfreetype', '-lxml2']


Following the discussion from other threads, i have put this in my `ns-3.28/wscript`  :

    have_zmq = conf.check_cfg( package='libzmq', args=['--cflags', '--libs'], uselib_store='ZMQ', mandatory=True)
   conf.env['ENABLE_ZMQ'] = have_zmq
   conf.report_optional_feature("ZMQ", "libzmq", conf.env['ENABLE_ZMQ'], "ZMQ not found")  
    conf.env.append_value('CXXFLAGS', '-DNO_INT_SIZE_CHECK')
   conf.env.append_value('CXXFLAGS', '-Wall')
   conf.env.append_value('CXXFLAGS', '-g')
   conf.env.append_value('CXXFLAGS', '-DNDEBUG')
   conf.env.append_value('CXXFLAGS', '-pipe')                    
    # conf.env.append_value('INCLUDES', '<path_to_include_folder>')
   # conf.env.append_value('LINKFLAGS', '-L<path_to_lib_folder>')
   conf.env.append_value('LINKFLAGS', '-lzmq' )
   # ==========================================================================

How can I solve this problem?

arshi mohini

unread,
Feb 12, 2019, 9:05:32 PM2/12/19
to ns-3-users
Hi Vishnu,

I am facing similar issue. From what I infer, the issue is not with my linking of ns3 and ZeroMQ. I have attached a screenshot of the error that I am getting. You can see that my program can successfully invoke zmq.hpp from /usr/include path but crashes when it can't find function definitions like 'zmq_errno' `zmq_ctx_new' etc. Please let me know if you were able to resolve the issue and how?

Screenshot from 2019-02-12 21-05-03.png

Tom Henderson

unread,
Feb 12, 2019, 10:40:04 PM2/12/19
to ns-3-...@googlegroups.com
On 2/12/19 6:05 PM, arshi mohini wrote:
> Hi Vishnu,
>
> I am facing similar issue. From what I infer, the issue is not with my
> linking of ns3 and ZeroMQ. I have attached a screenshot of the error
> that I am getting. You can see that my program can successfully invoke
> zmq.hpp from /usr/include path but crashes when it can't find function
> definitions like 'zmq_errno' `zmq_ctx_new' etc. Please let me know if
> you were able to resolve the issue and how?

Your program is not successfully linking because the libzmq is not found
on your library path.

Can you try finding where the libzmq.so.0 library is located, and then
add that directory to your library path? For instance, if it is in
/usr/local/lib:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

and then try again.

- Tom

Henrique Bastos

unread,
Dec 13, 2022, 2:54:09 PM12/13/22
to ns-3-users
I'm facing this same issue, I can find the CPPZMQ, but it looks like that it's not linked with libzmq.

I was able to use it normally with wscript, but now using cmake and ns3 3.36, it's not working.

/usr/bin/ld: CMakeFiles/scratch_scratch-simulator.dir/scratch-simulator.cc.o: in function `zmq::context_t::close()':
/usr/local/include/zmq.hpp:868: undefined reference to `zmq_ctx_term'
/usr/bin/ld: CMakeFiles/scratch_scratch-simulator.dir/scratch-simulator.cc.o: in function `zmq::error_t::what() const':
/usr/local/include/zmq.hpp:296: undefined reference to `zmq_strerror'
/usr/bin/ld: CMakeFiles/scratch_scratch-simulator.dir/scratch-simulator.cc.o: in function `zmq::error_t::error_t()':
/usr/local/include/zmq.hpp:292: undefined reference to `zmq_errno'
/usr/bin/ld: CMakeFiles/scratch_scratch-simulator.dir/scratch-simulator.cc.o: in function `zmq::context_t::context_t()':
/usr/local/include/zmq.hpp:798: undefined reference to `zmq_ctx_new'

collect2: error: ld returned 1 exit status
gmake[2]: *** [scratch/CMakeFiles/scratch_scratch-simulator.dir/build.make:103: /home/fhb/5glena_v2x/ns-3-dev/build/scratch/ns3-dev-scratch-simulator-default] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:16926: scratch/CMakeFiles/scratch_scratch-simulator.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
Finished executing the following commands:
cd cmake-cache; cmake --build . -j 11 ; cd ..

Gabriel Ferreira

unread,
Dec 14, 2022, 12:19:07 PM12/14/22
to ns-3-users
What isn't working? You don't even seem to be linking zmq to the scratches. 
Add the following to the CMakeLists.txt in the scratch directory.

find_library(ZMQ zmq)
link_libraries(${ZMQ})

Henrique Bastos

unread,
Dec 14, 2022, 1:57:55 PM12/14/22
to ns-3-users
Thanks, Gabriel!!!

Now it is working. I was adding it to the main CMakeLists.txt and not inside the scratch folder.

djab _eR

unread,
Nov 17, 2023, 2:30:09 PM11/17/23
to ns-3-users
where can i find the main CMakeLists.txt for ndnsim ?
Reply all
Reply to author
Forward
0 new messages