zeromq / cppzmq

Header-only C++ binding for libzmq
http://www.zeromq.org
MIT License
1.94k stars 757 forks source link

Undefined reference to zmq.hpp functions in vscode in ubuntu 18.04 LTS #495

Closed swetha9198 closed 3 years ago

swetha9198 commented 3 years ago

This is my error: /usr/bin/g++ -g -pthread -lzmq /home/swetha/work/GUI-RANEMU/GUI-RANEMU.cpp -o /home/swetha/work/GUI-RANEMU/GUI-RANEMU /tmp/ccefaiXb.o: In function zmq::error_t::error_t()': /usr/local/include/zmq.hpp:290: undefined reference tozmq_errno' /tmp/ccefaiXb.o: In function zmq::error_t::what() const': /usr/local/include/zmq.hpp:294: undefined reference tozmq_strerror' /tmp/ccefaiXb.o: In function zmq::message_t::message_t()': /usr/local/include/zmq.hpp:399: undefined reference tozmq_msg_init' /tmp/ccefaiXb.o: In function zmq::message_t::~message_t()': /usr/local/include/zmq.hpp:494: undefined reference tozmq_msg_close' /tmp/ccefaiXb.o: In function zmq::message_t::data()': /usr/local/include/zmq.hpp:574: undefined reference tozmq_msg_data' /tmp/ccefaiXb.o: In function zmq::context_t::context_t()': /usr/local/include/zmq.hpp:784: undefined reference tozmq_ctx_new' /tmp/ccefaiXb.o: In function zmq::context_t::close()': /usr/local/include/zmq.hpp:854: undefined reference tozmq_ctx_term' /tmp/ccefaiXb.o: In function zmq::detail::socket_base::bind(char const*)': /usr/local/include/zmq.hpp:1801: undefined reference tozmq_bind' /tmp/ccefaiXb.o: In function zmq::detail::socket_base::send(zmq::const_buffer, zmq::send_flags)': /usr/local/include/zmq.hpp:1891: undefined reference tozmq_send' /usr/local/include/zmq.hpp:1894: undefined reference to zmq_errno' /tmp/ccefaiXb.o: In functionzmq::detail::socket_base::send(zmq::message_t&, zmq::send_flags)': /usr/local/include/zmq.hpp:1901: undefined reference to zmq_msg_send' /usr/local/include/zmq.hpp:1904: undefined reference tozmq_errno' /tmp/ccefaiXb.o: In function zmq::socket_t::socket_t(zmq::context_t&, int)': /usr/local/include/zmq.hpp:2144: undefined reference tozmq_socket' /tmp/ccefaiXb.o: In function zmq::socket_t::close()': /usr/local/include/zmq.hpp:2184: undefined reference tozmq_close' collect2: error: ld returned 1 exit status

Build finished with error(s). The terminal process terminated with exit code: -1.

I installed libzmq and cppzmq. I added -lzmq in the tasks.json file of my vscode project but am still getting this error. Can anyone please help?

albestro commented 3 years ago

Given the few info you provided, I would think it's a problem in your setup rather than in the library.

Being a linking problem, I suggest you to try manually specifying the exact libzmq library you are using via an absolute path (e.g. something similar to -l/usr/local/lib/libzmq.so depending on where you installed it). Moreover, I will also check that this library path for libzmq was also the one used during the build of cppzmq.

swetha9198 commented 3 years ago

I used sudo install libzmq-dev to install the libzmq library, and manually added the cppzmq.h to /usr/include folder

albestro commented 3 years ago

It does not sound as the cleanest way to set it up, but AFAICT it might be enough.

I will check: