【OpenCV】undefined reference to `cv::dnn::dnn4_v20191202::Net::~Net()‘

Linux环境下使用opencv的dnn模块调用yolov4遇到的坑(纯CPU)

1. 改CMakeList.txt

向CMakeLists.txt中的

find_package(OpenCV 4 REQUIRED opencv_core opencv_imgproc opencv_highgui opencv_calib3d opencv_videoio opencv_imgcodecs )

添加opencv_dnn,即改成

find_package(OpenCV 4 REQUIRED opencv_core opencv_imgproc opencv_highgui opencv_calib3d opencv_videoio opencv_imgcodecs opencv_dnn )

2. 改Makefile

或者也可以直接在Makefile中添加编译选项

BUILD_FLAGS += -l opencv_dnn

3. Makefile中指定的OpenCV头文件和库文件的版本可能不匹配

我遇到的情况是,在makefile中指定opencv库文件路径是4.2.0的,但是指定的头文件路径是4.4.0的,所以它连cv::Mat::Mat()都是undefined,改成一致的就好了

如果用pkg-config配置好opencv环境的话,makefile这样写就不会遇到头文件库文件opencv版本不一致的问题:

CXX = aarch64-linux-gnu-g++

INCLUDE = $(shell pkg-config --cflags opencv4)  #获得opencv相关头文件路径
LIBS = $(shell pkg-config --libs opencv4) #获得opencv扩展库。

SOURCES = test.cpp 
TARGET = test

$(TARGET):$(SOURCES)
	@$(CXX) -std=c++11 -O1 -o $(TARGET) $(SOURCES) $(INCLUDE) $(LIBS)

clean:
	rm -rf $(TARGET) *.o

你可能感兴趣的:(各路问题汇总,opencv,opencv,dnn,c++)