使用 makefile 编译时对“zmq_ctx_new”的未定义引用

undefined reference to `zmq_ctx_new' when compiling using makefile

我在 linux-ubuntu 风格的 NVIDIA Jetson Xavier 上安装了 zmq,如下所示:

sudo apt-get install libzmq3-dev

我在 C++ 程序中创建了一个使用 PUSH/PULL 架构的简单 ZMQ 服务器。我可以使用 CLI 编译它,如下所示:

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

然后我将这段代码集成到我的更大的应用程序中,其中包含更多的库和依赖项。这是使用 makefile (makefile.config) 编译的。要编译更新后的应用程序,我需要将 -lzmq 标志添加到原始 makefile。这就是我所做的:

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

但是在 运行 sudo make clean && sudo make,我得到

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

Makefile 很简单

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

原文makefile.config可以找到here

我觉得我搞砸了 makefile 因为 zmq 在使用 gcc.

编译时工作

好的,正如@madscientist 指出的那样,我错误地将链接器标志 -lzmq 添加到编译器行,这意味着只包含编译标志而不包含链接器标志。

这是我所做的更改:

 COMMON_LIBS += $(CUDART_LIB)
+COMMON_LIBS += -lzmq