第一次接触OpenCV,搭建好了环境,开始编写第一个demo工程,结果编译报错,最后国外大神给出解决方案。
错误信息:
:-1: error: main.o: undefined reference to symbol 'cv::imread(cv::String const&, int)'
:-1: error: note: 'cv::imread(cv::String const&, int)' is defined in DSO /usr/local/lib/libopencv_imgcodecs.so.3.2 so try adding it to the linker command line
/usr/local/lib/libopencv_imgcodecs.so.3.2:-1: error: could not read symbols: Invalid operation
:-1: error: collect2: ld returned 1 exit status
解决方式:
在.pro文件中的 LIB+=后面再添加一行/usr/local/lib/libopencv_imgcodecs.so ,整个.pro文件:
QT += core
QT -= gui
TARGET = opencv_test1
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
INCLUDEPATH += /usr/local/include \
/usr/local/include/opencv \
/usr/local/include/opencv2
LIBS += /usr/local/lib/libopencv_highgui.so \
/usr/local/lib/libopencv_core.so \
/usr/local/lib/libopencv_imgproc.so \
SOURCES += main.cpp
PS:
估计出现这个问题的同学都是照着网上的文章进行的,我估计有可能是版本更新的问题导致。