我正在运行opencv和qt.I我在执行cvLoadImage时成功添加了opencv.But的包含,但是存在链接器错误。
这是我的代码:
void MainWindow:on_pushButton_clicked()
{
img = cvLoadImage("C:\\Users\\MLS-PROGRAMER\\Documents\\Visual Studio 2010\\Projects\\Image_processing\\Image_processing \\thres.png");
// cvNamedWindow("Image",CV_WINDOW_AUTOSIZE);
// cvShowImage("Image", img);
// cvWaitKey(40);
}
这是错误消息:
mainwindow.obj:-1: error: LNK2019: unresolved external symbol _cvLoadImage referenced in function "private: void __thiscall MainWindow:n_pushButton_clicked(void)" (?on_pushButton_clicked@MainWindow@@AAEXXZ)
debug\FIDAS.exe:-1: error: LNK1120: 1 unresolved externals
我的项目文件是这样的
#-------------------------------------------------
#
# Project created by QtCreator 2012-05-29T10:31:40
#
#-------------------------------------------------
QT += core gui
TARGET = FIDAS
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += C:\OpenCV2.3\opencv\build\include\opencv2\core \
C:\OpenCV2.3\opencv\build\include\opencv \
C:\OpenCV2.3\opencv\build\include\opencv2\imgproc \
C:\OpenCV2.3\opencv\build\gpu\x64\lib \
CONFIG(release,debug|release)
{
LIBS += C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_calib3d231.lib \
C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_contrib231.lib \
C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_core231.lib \
C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_features2d231.lib \
C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_flann231.lib \
C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_gpu231.lib \
C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_haartraining_engine.lib \
C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_highgui231.lib \
C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_imgproc231.lib \
C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_legacy231.lib \
C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_ml231.lib \
C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_objdetect231.lib \
C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_ts231.lib \
C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_video231.lib \
}
CONFIG(debug,debug|release)
{
LIBS += C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_calib3d231d.lib \
C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_contrib231d.lib \
C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_core231d.lib \
C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_features2d231d.lib \
C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_flann231d.lib \
C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_gpu231d.lib \
C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_haartraining_engined.lib \
C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_highgui231d.lib \
C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_imgproc231d.lib \
C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_legacy231d.lib \
C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_ml231d.lib \
C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_objdetect231d.lib \
C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_ts231d.lib \
C:\OpenCV2.3\opencv\build\gpu\x64\lib\opencv_video231d.lib \
}
对这个问题的任何帮助都会很棒。?
答案 0 :(得分:2)
我对我自己的项目使用这样的配置:
LIBS += D:/OpenCV-2.3.0/build/lib/libopencv_core230.dll.a
我使用C ++ API而不是使用C API,即imread
而不是cvLoadImage
。
答案 1 :(得分:2)
您应该实际指定链接路径(在哪里找到库),然后指定要链接的库列表:
LIBS += -L C:\OpenCV2.3\opencv\build\gpu\x64\lib -lopencv_contrib231 -lopencv_core231 -lopencv_features2d231 ...
答案 2 :(得分:1)
Step 8为所有体系结构描述了它。
基本上,您必须使用-L指定库路径,然后使用
添加库文件 -l<libname_without_extension>
对于unix(安装在默认位置):
unix: LIBS += -lopencv_core
unix: LIBS += -lopencv_highgui
对于Windows(你的问题):
win32: LIBS += -L C:\OpenCV2.3\opencv\build\gpu\x64\lib\ -lopencv_core231