Adding OpenCV library to a Qt project

Sysprogs forums Forums VisualGDB Adding OpenCV library to a Qt project

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #8015
    gomore
    Participant

    Hello.

    I have a Qt5 based project created with VisualGDB . I want to add the OpenCV library to the project but I´m not abble to do this and I can´t find any tutorial or help to manage with it. Could somebody help me please.

    Thank you.

    #8018
    support
    Keymaster

    Hi,

    We would recommend first ensuring that you can add the library to a basic “Hello, World” project by following one of our OpenCV tutorials. Once that works, simply take a note of the include paths and library names added to the Hello, World project and add them manually to the Qt project via VisualGDB Project Properties. This will let your Qt project use OpenCV the same way as the Hello, World project does.

    #8025
    gomore
    Participant

    Thank you for the answer but I´m trying to follow this steps but still is not working. I´ll explain better what I do, so maybe you can understand me much better.

    I have a “Hellow World” OpenCV project working based in one of your tutorials based in CMake. Lets think that I only need highgui.hpp, highgui.h and imgproc.hpp header files for my new Qt based project.This files are included in …/include/opencv2/highgui and …/include/opencv2/imgproc paths.

    Now I create the Qt project and open the  VisualGDB Project Properties. And here is where I have my doubts. I add the two paths of the include directories in the “Include directories” gap. And then I add the three files names in the “Library names” gap. But when I press Apply, I get this error from VisualGDB:

    Tool arguments: -Wl,–start-group “…….\Local\Temp\/VisualGDB_ToolchainTestProgram.o” -o “………..\Local\Temp\/VisualGDB_ToolchainTestProgram” -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -IC:/sysgcc/raspberry/arm-linux-gnueabihf/sysroot/usr/lib/arm-linux-gnueabihf/qt5/mkspecs/arm-linux-gnueabihf -I. -I=/usr/local/include/opencv2/highgui -I=/usr/local/include/opencv2/imgproc -I=/usr/share/OpenCV -IC:/sysgcc/raspberry/arm-linux-gnueabihf/sysroot/usr/include/arm-linux-gnueabihf/qt5 -IC:/sysgcc/raspberry/arm-linux-gnueabihf/sysroot/usr/include/arm-linux-gnueabihf/qt5/QtWidgets -IC:/sysgcc/raspberry/arm-linux-gnueabihf/sysroot/usr/include/arm-linux-gnueabihf/qt5/QtGui -IC:/sysgcc/raspberry/arm-linux-gnueabihf/sysroot/usr/include/arm-linux-gnueabihf/qt5/QtCore -IDebug -IDebug -lhighgui.hpp -lhighgui.h -limgproc.hpp -Lc:/sysgcc/raspberry/arm-linux-gnueabihf/sysroot/usr/lib/arm-linux-gnueabihf -lQt5Widgets -lQt5Gui -lQt5Core -lGLESv2 -lpthread -pipe -Wno-psabi -ggdb -g -Wall -W -D_REENTRANT -fPIE -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -pipe -Wno-psabi -ggdb -g -Wall -W -D_REENTRANT -fPIE -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -Wl,–end-group
    c:/sysgcc/raspberry/bin/../lib/gcc/arm-linux-gnueabihf/4.9/../../../../arm-linux-gnueabihf/bin/ld.exe: cannot find -lhighgui.hpp
    c:/sysgcc/raspberry/bin/../lib/gcc/arm-linux-gnueabihf/4.9/../../../../arm-linux-gnueabihf/bin/ld.exe: cannot find -lhighgui.h
    c:/sysgcc/raspberry/bin/../lib/gcc/arm-linux-gnueabihf/4.9/../../../../arm-linux-gnueabihf/bin/ld.exe: cannot find -limgproc.hpp
    collect2.exe: error: ld returned 1 exit status

     

    Any suggestions??? Thank you in advance.

    #8034
    support
    Keymaster

    Hi,

    It looks like you are trying to add header files (.hpp) to the library list. This won’t work as those are different types of files. Header files contain definitions of your functions and you should be referenced by adding their directories to the Include Directories field. Then the #include<> directories will handle them properly. When this is not setup properly, you will get errors like “cannot open file xxx.h”.

    Library files (.a or .so) contain compiled implementations of your functions and should be added to the Library Names field (without the ‘lib’ prefix and extension, more details here). When some libraries are missing, you will typically get errors like “unresolved reference to xxx”.

    We would recommend first solving the problems with the header files (the code should at least compile and then get stuck at ‘unresolved reference’ problems) and then add the missing libraries to VisualGDB Project Properties. You can find the libraries by simply searching the OpenCV build directory for .a and .so files.

    #8047
    gomore
    Participant

    Finally it worked!! Thank you so mutch. But I have had to add the full paths of the libraries needed in the additional linker inputs gap, as I was cross-compiling for an embedded linux toolchain.

    Again thank you so much.

    #8053
    support
    Keymaster

    Good to know it works. Note that you can simply put the library directories in the ‘library directories’ field and library names without ‘lib’ and ‘.a’ or ‘.so’ to the “library names” if you want to simplify your setup.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.