0

I installed zmq on my linux-ubuntu flavoured NVIDIA Jetson Xavier as follows:

sudo apt-get install libzmq3-dev

I created a simple ZMQ server that uses PUSH/PULL architecture in a C++ program. I am able to compile it using CLI as follows:

$ gcc -Wall -g server.cpp -lstdc++ -lzmq -o out

Then I integrate this code in my larger application with more libraries and dependencies. This is compiled using a makefile (makefile.config). To compile the updated application, I need to add the -lzmq flag to the original makefile. This is what I do:

-COMMON_FLAGS += -Wall -Wno-deprecated-declarations -std=c++11 $(INCPATHS)
+COMMON_FLAGS += -Wall -g -lstdc++ -lzmq -Wno-deprecated-declarations -std=c++11 $(INCPATHS)

But on running sudo make clean && sudo make, I get

Linking: ../../bin/sample_uff_mask_rcnn_debug
../../bin/dchobj/sampleUffMaskRCNN.o: In function `main':
/home/virus/Desktop/optimisation/custom-inference-mrcnn/maskRCNN/sampleUffMaskRCNN.cpp:717: undefined reference to `zmq_ctx_new'
/home/virus/Desktop/optimisation/custom-inference-mrcnn/maskRCNN/sampleUffMaskRCNN.cpp:718: undefined reference to `zmq_socket'
/home/virus/Desktop/optimisation/custom-inference-mrcnn/maskRCNN/sampleUffMaskRCNN.cpp:724: undefined reference to `zmq_ctx_new'
/home/virus/Desktop/optimisation/custom-inference-mrcnn/maskRCNN/sampleUffMaskRCNN.cpp:725: undefined reference to `zmq_socket'
/home/virus/Desktop/optimisation/custom-inference-mrcnn/maskRCNN/sampleUffMaskRCNN.cpp:726: undefined reference to `zmq_connect'
/home/virus/Desktop/optimisation/custom-inference-mrcnn/maskRCNN/sampleUffMaskRCNN.cpp:737: undefined reference to `zmq_recv'
collect2: error: ld returned 1 exit status
../Makefile.config:301: recipe for target '../../bin/sample_uff_mask_rcnn_debug' failed
make: *** [../../bin/sample_uff_mask_rcnn_debug] Error 1

The Makefile is simple

OUTNAME_RELEASE = sample_uff_mask_rcnn
OUTNAME_DEBUG   = sample_uff_mask_rcnn_debug
EXTRA_DIRECTORIES = ../common
.NOTPARALLEL:
MAKEFILE ?= ../Makefile.config
include $(MAKEFILE)

The original makefile.config can be found here

I feel that I am messing up with the makefile because zmq works when compiling using gcc.

Pe Dro
  • 2,651
  • 3
  • 24
  • 44
  • 1
    You haven't actually asked a question or shown a problem here. – MadScientist Nov 15 '21 at 14:20
  • Sorry for missing it. I updated the question – Pe Dro Nov 15 '21 at 14:26
  • 1
    Well, we have no idea what your makefile does. However, it's almost certainly wrong to add libraries to a variable named `COMMON_FLAGS` as they should only be put into the link line, not the compile lines; the presence of `INCPATHS` here implies these flags are added to compile lines. Secondly, the order of libraries is critically important: they must come AFTER all the object files. So in short, this is the wrong variable to add linker options like `-lzmq` to. You'll have to find the variable containing libraries to link. And, you should not add `-lstdc++` to your link line. – MadScientist Nov 15 '21 at 14:49

1 Answers1

0

Ok so as @madscientist pointed out, I was wrongly adding the linker flag -lzmq to the compiler line, which was meant to only contain compilation flags and not linker flags.

This is the change I made:

 COMMON_LIBS += $(CUDART_LIB)
+COMMON_LIBS += -lzmq
Pe Dro
  • 2,651
  • 3
  • 24
  • 44