开发者

Using OpenCV in QTCreator (linking problem)

开发者 https://www.devze.com 2022-12-28 06:28 出处:网络
I have a problem with the linking simpliest test program in QTCreator: CODE: #include <QtCore/QCoreApplication>

I have a problem with the linking simpliest test program in QTCreator:

CODE:

#include <QtCore/QCoreApplication>
#include <cv.h>

#include <highgui.h>
#include <cxcore.hpp>

using namespace cv;

int _tmain(int argc, _TCHAR* argv[])
{
    cv::Mat M(7,7,CV_32FC2,Scalar(1,3));
    return 0;
}

.pro file:

QT       -= gui
TARGET    = testopencv
开发者_如何学PythonCONFIG   += console
CONFIG   -= app_bundle
INCLUDEPATH += C:/OpenCV2_1/include/opencv
TEMPLATE = app

LIBS += C:/OpenCV2_1/lib/cxcore210d.lib \
    C:/OpenCV2_1/lib/cv210d.lib \
    C:/OpenCV2_1/lib/highgui210d.lib\
    C:/OpenCV2_1/lib/cvaux210d.lib
SOURCES += main.cpp

I've tried to use -L and -l like LIBS += -LC:/OpenCV2_1/lib -lcxcored

And in .pro file:

QMAKE_LIBDIR += C:/OpenCV2_1/lib/Debug

LIBS += -lcxcore210d \
-lcv210d \
-lhighgui210d 

The errors are like:

debug/main.o:C:\griskin\test\app\testopencv/../../../../OpenCV2_1/include/opencv/cxcore.hpp:97: undefined reference to cv::format(char const*, ...)'

Could anyone help me? Thanks!

In Visual Studio it works but I need it works in QTCreator..


Qt uses the MinGW compiler and linker. It will happily link OpenCV .libs when you use the C interface. However due to ABI issues, it will not link C++ modules.

You will have to either restrict yourself to the C interfaces only (i.e. no cv::Mat), or get OpenCV to compile with MinGw (or compile Qt in/with VS). Also, see this thread.


This is what my .pro file looks like

INCLUDEPATH += C:\\opencv\\release\\install\\include\

LIBS += -LC:\\opencv\\release\\install\\bin \
    -lopencv_core240 \
    -lopencv_highgui240 \
    -lopencv_imgproc240 \
    -lopencv_features2d240 \
    -lopencv_calib3d240 \

and replace

#include <cv.h>

with

#include <opencv/cv.h>

Above .pro file works perfect for me. I have used mingw to compile OpenCV and using mingw compiler tool chain in Qt.


It seems that QtCreator cannot locate lib files. Try specifying the include file and libs as follows.

INCLUDEPATH += C:/OpenCV2_1/build/include/

LIBS += C:/OpenCV2_1/build/gpu/x86/lib/cxcore210d.lib

you should refer to build folder if you're using pre-build version of opencv.

(I recommend pre-build version if you're not that familiar with opencv)

0

精彩评论

暂无评论...
验证码 换一张
取 消