ubuntu系统,先装了opencv2.4.9,后来又安装了opencv3.0,qt下编译项目报错:
:-1: error: tracker_run.o: undefined reference to symbol '_ZN2cv7imwriteERKNS_6StringERKNS_11_InputArrayERKSt6vectorIiSaIiEE'
/usr/local/lib/libopencv_imgcodecs.so.3.0:-1: error: error adding symbols: DSO missing from command line
:-1: error: collect2: error: ld returned 1 exit status
解决方式:在项目的.pro文件中:
把imgcodecs头文件和库都引用上,就不报错了
#INCLUDEPATH += /usr/local/include/opencv2/imgcodecs
/usr/local/lib/libopencv_core.so\
/usr/local/lib/libopencv_features2d.so \
/usr/local/lib/libopencv_flann.so \
/usr/local/lib/libopencv_highgui.so \
/usr/local/lib/libopencv_imgcodecs.so \
项目过去很久了,从网上找个例子:
https://github.com/jacke121/cpp-qt5.9.2-opencv3.4.3
#-------------------------------------------------
#
# Project created by QtCreator 2019-02-28T00:25:57
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Demo
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
INCLUDEPATH += \
E:\opencv\install\include \
E:\opencv\install\include\opencv \
E:\opencv\install\include\opencv2 \
LIBS += \
E:\opencv\install\x64\vc15\lib\opencv_world343d.lib \
win32: LIBS += -LE:/Python/Python36/libs/ -lpython36
INCLUDEPATH += E:/Python/Python36/include
DEPENDPATH += E:/Python/Python36/include
win32:!win32-g++: PRE_TARGETDEPS += E:/Python/Python36/libs/python36.lib
else:win32-g++: PRE_TARGETDEPS += E:/Python/Python36/libs/libpython36.a