简体   繁体   中英

How to compile Opencv 3.1 with QT on a x64 machine?

I'm using Opencv 3.1, Cmake 3.6.0, Cuda 7.5, Visual Studio 2013.
I successfully compile my own Opencv libraries, on a x64 machine and I am able now to use CUDA module.
I tried to compile it with qt 5.6.1 but I couldn't.
When I select the checkbox WITH > QT on cmake-gui I have no problems. But when I build the ALL BUILD project it throws me the followings:

window_QT.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const ...

I've already use the qt instaler and compile qt from source.
I've already put the lib and bin directories on the VSproject, but I cannot resolve the linking problem.
Thanks..

For OpenCV 3.1, here is the configuration that worked for me:

TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp
TARGET = main

INCLUDEPATH += C:/opencv-3.1.0/opencv/build/include
LIBS += -LC:/opencv-3.1.0/opencv/build/x64/vc14/lib
LIBS += -LC:/opencv-3.1.0/opencv/build/x64/vc14/bin

CONFIG(debug,debug|release)
{
    LIBS += -lopencv_world310d
}

CONFIG(release,debug|release)
{
    LIBS += -lopencv_world310
}

To add Qt support to OpenCV 3.1, please follow these instructions: https://gist.github.com/BartG95/1ce8ba1e9c25ec3698d1

and add /APPCONTAINER:NO to the following properties during the build process, otherwise it will not work:

CMAKE_EXE_LINKER_FLAGS
CMAKE_MODULE_LINKER_FLAGS
CMAKE_SHARED_LINKER_FLAGS

Here is my working .pro file:

TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp
TARGET = main

INCLUDEPATH += D:/Fouad/dev/Libs/opencv-3.1.0/opencv/build-with-qt-support/install/include
INCLUDEPATH += D:/Fouad/dev/Libs/opencv-3.1.0/opencv/dep/tbb2017_20161004oss/include
LIBS += -LD:/Fouad/dev/Libs/opencv-3.1.0/opencv/build-with-qt-support/install/x64/vc14/bin
LIBS += -LD:/Fouad/dev/Libs/opencv-3.1.0/opencv/build-with-qt-support/install/x64/vc14/lib
LIBS += -LD:/Fouad/dev/Libs/opencv-3.1.0/opencv/build-with-qt-support/install/x64/vc14/staticlib
LIBS += -LD:/Fouad/dev/Libs/opencv-3.1.0/opencv/dep/tbb2017_20161004oss/bin/intel64/vc14_ui
LIBS += -LD:/Fouad/dev/Libs/opencv-3.1.0/opencv/dep/tbb2017_20161004oss/lib/intel64/vc14_ui
LIBS += -lippicvmt

CONFIG(debug, debug|release)
{
    LIBS += -lopencv_calib3d310d
    LIBS += -lopencv_core310d
    LIBS += -lopencv_features2d310d
    LIBS += -lopencv_flann310d
    LIBS += -lopencv_highgui310d
    LIBS += -lopencv_imgcodecs310d
    LIBS += -lopencv_imgproc310d
    LIBS += -lopencv_ml310d
    LIBS += -lopencv_objdetect310d
    LIBS += -lopencv_photo310d
    LIBS += -lopencv_shape310d
    LIBS += -lopencv_stitching310d
    LIBS += -lopencv_superres310d
    LIBS += -lopencv_video310d
    LIBS += -lopencv_videoio310d
    LIBS += -lopencv_videostab310d
    LIBS += -ltbb_debug
    LIBS += -ltbb_preview_debug
    LIBS += -ltbbmalloc_debug
    LIBS += -ltbbmalloc_proxy_debug
    LIBS += -ltbbproxy_debug
}

CONFIG(release, debug|release)
{
    LIBS += -lopencv_calib3d310
    LIBS += -lopencv_core310
    LIBS += -lopencv_features2d310
    LIBS += -lopencv_flann310
    LIBS += -lopencv_highgui310
    LIBS += -lopencv_imgcodecs310
    LIBS += -lopencv_imgproc310
    LIBS += -lopencv_ml310
    LIBS += -lopencv_objdetect310
    LIBS += -lopencv_photo310
    LIBS += -lopencv_shape310
    LIBS += -lopencv_stitching310
    LIBS += -lopencv_superres310
    LIBS += -lopencv_video310
    LIBS += -lopencv_videoio310
    LIBS += -lopencv_videostab310
    LIBS += -ltbb
    LIBS += -ltbb_preview
    LIBS += -ltbbmalloc
    LIBS += -ltbbmalloc_proxy
    LIBS += -ltbbproxy
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM