在发布模式下构建QT / OpenCV应用程序时遇到链接问题。
开发环境是QT 5.8,QtCreator4.2.1和OpenCV 3.4.2
我有两个类(MainWindow和ScanBoxUiItem)都使用了OpenCV方法,例如:Mat :: zeros,Mat :: copyTo,cv :: resize。
在“调试”模式下,一切正常,可以启动应用程序而不会出现任何问题。这应该意味着代码正确。
但是在切换到发布模式后,对ScanBoxUiItem类抛出LNK2019错误。在我注释掉调用OpenCV API的代码之后,构建就可以了。但是MainWindow中调用OpenCV API的代码仍然存在并且可以正常工作,这意味着链接应该仍然有效。但是,为什么对ScanBoxUiItem的链接在“发布”模式下不起作用?
下面是.pro文件:
#-------------------------------------------------
#
# Project created by QtCreator 2018-08-21T16:59:14
#
#-------------------------------------------------
include(thirdParty/qtxlsx/src/xlsx/qtxlsx.pri)
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = TrafficAnalyze
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as 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
TRANSLATIONS += messages.ts
SOURCES += main.cpp\
mainwindow.cpp \
addscanboxdialog.cpp \
scanboxinfo.cpp \
scanboxuiitem.cpp \
videowindow.cpp \
scaninfo.cpp \
videohelper.cpp \
analysisdialog.cpp \
analysisresult.cpp \
scanboxinfocontroller.cpp
HEADERS += mainwindow.h \
addscanboxdialog.h \
scanboxinfo.h \
constants.h \
scanboxuiitem.h \
videowindow.h \
scaninfo.h \
videohelper.h \
analysisdialog.h \
analysisresult.h \
scanboxinfocontroller.h
FORMS += mainwindow.ui \
addscanboxdialog.ui \
scanboxuiitem.ui \
videowindow.ui \
analysisdialog.ui \
analysisresult.ui
INCLUDEPATH += D:/Download/Software/DevTools/opencv/build/include
CONFIG(debug, debug|release): {
LIBS += -LD:/Download/Software/DevTools/opencv/build/x64/vc14/lib \
-lopencv_world340d
} else:CONFIG(release, debug|release): {
LIBS += -LD:/Download/Software/DevTools/opencv/build/x64/vc14/lib \
-lopencv_world340
}
DISTFILES += \
messages.qm \
messages.ts
RESOURCES += \
icons.qrc
以下是错误:
> D:\Qt\Qt5.8.0\Tools\QtCreator\bin\jom.exe -f Makefile.Release link /NOLOGO /DYNAMICBASE /NXCOMPAT /INCREMENTAL:NO /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:release\TrafficAnalyze.exe @C:\Users\Shaoyie\AppData\Local\Temp\TrafficAnalyze.exe.6740.32.jom
> scanboxuiitem.obj : error LNK2019: unresolved external symbol "public: void __cdecl cv::Mat::copyTo(class cv::debug_build_guard::_OutputArray const &)const " (?copyTo@Mat@cv@@QEBAXAEBV_OutputArray@debug_build_guard@2@@Z),referenced in function "public: void __cdecl ScanBoxUiItem::refreshScanBoxImg(class cv::Mat)" (?refreshScanBoxImg@ScanBoxUiItem@@QEAAXVMat@cv@@@Z) scanboxuiitem.obj : error LNK2019: unresolved external symbol "void
__cdecl cv::resize(class cv::debug_build_guard::_InputArray const &,class cv::debug_build_guard::_OutputArray const &,class cv::Size_<int>,double,double,int)" (?resize@cv@@YAXAEBV_InputArray@debug_build_guard@1@AEBV_OutputArray@31@V?$Size_@H@1@NNH@Z),referenced in function "public: void __cdecl ScanBoxUiItem::refreshScanBoxImg(class cv::Mat)" (?refreshScanBoxImg@ScanBoxUiItem@@QEAAXVMat@cv@@@Z) scanboxuiitem.obj : error LNK2019: unresolved external symbol "void
__cdecl cv::cvtColor(class cv::debug_build_guard::_InputArray const &,class cv::debug_build_guard::_OutputArray const &,int,int)" (?cvtColor@cv@@YAXAEBV_InputArray@debug_build_guard@1@AEBV_OutputArray@31@HH@Z),referenced in function "public: void __cdecl ScanBoxUiItem::refreshScanBoxImg(class cv::Mat)" (?refreshScanBoxImg@ScanBoxUiItem@@QEAAXVMat@cv@@@Z) release\TrafficAnalyze.exe : fatal error LNK1120: 3 unresolved externals
执行qmake或删除Rlease / Debug / Makefile *文件无济于事。
任何人都可以提出一个想法来识别此问题吗?