Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QT 5.12.3, OpenCV 3.4.3, Rasberry Pi 3B+, Cross-Compilation failure



  • I recently install QT 5.12.3 for cross compilation on a Raspberry Pi 3B+ running Rasbian Stretch, using this [https://mechatronicsblog.com/cross-compile-and-deploy-qt-5-12-for-raspberry-pi/] guide. Before this I installed OpenCV 3.4.3 using this [https://github.com/jayrambhia/Install-OpenCV] script from Github.

    I have everything set up and I tested the cross compilation without using the OpenCV libraries. Then when I attempt to compile something that uses an OpenCV function the compiler tells me that there are undefined references to OpenCV functions. I am unsure of the reason for why it is failing during compilation. I have included the relavant portiong of my code below

    Could it be related to the way I compiled the OpenCV libraries? In the script the cmake command has the WITH_QT=ON flag.

    Qt recognizes the OpenCV functions, as they appear in the dropdown as I type them in. Has anyone experienced this before?

    I am including the OpenCV libraries in the .pro file like this:

    INCLUDEPATH += "/usr/local/include"
    LIBS += -L/usr/local/lib/libopencv_highgui.so
    LIBS += -L/usr/local/lib/libopencv_core.so
    LIBS += -L/usr/local/lib/libopencv_features2d.so
    LIBS += -L/usr/local/lib/libopencv_flann.so
    LIBS += -L/usr/local/lib/libopencv_imgcodecs.so
    LIBS += -L/usr/local/lib/libopencv_imgproc.so
    LIBS += -L/usr/local/lib/libopencv_objdetect.so
    LIBS += -L/usr/local/lib/libopencv_photo.so
    LIBS += -L/usr/local/lib/libopencv_shape.so
    LIBS += -L/usr/local/lib/libopencv_stitching.so
    LIBS += -L/usr/local/lib/libopencv_superres.so
    LIBS += -L/usr/local/lib/libopencv_video.so
    LIBS += -L/usr/local/lib/libopencv_videoio.so
    

    In the mainwindow.cpp file the OpenCV functions I used are:

    void MainWindow_QTt::on_pushButton_2_clicked()
    {
            namedWindow(window2,WINDOW_NORMAL);
            resizeWindow(window2, 240, 100);
    }
    

    The compiler output is this:

    /home/qt/Code/QT/build-QT_Test-RPi_Server-Debug/../QT_Test/mainwindow_qtt.cpp:50: undefined reference to `cv::namedWindow(cv::String const&, int)'
    /home/qt/Code/QT/build-QT_Test-RPi_Server-Debug/../QT_Test/mainwindow_qtt.cpp:51: undefined reference to `cv::resizeWindow(cv::String const&, int, int)'
    mainwindow_qtt.o: In function `cv::String::String(char const*)':
    /usr/local/include/opencv2/core/cvstd.hpp:602: undefined reference to `cv::String::allocate(unsigned int)'
    mainwindow_qtt.o: In function `cv::String::~String()':
    /usr/local/include/opencv2/core/cvstd.hpp:648: undefined reference to `cv::String::deallocate()'
    

    Thank you for your help.



  • @chris1092387456 could it be possible you have mixed Qt versions from the one you cross-compiled and the one it's used by the OpenCV install script you used.

    Assuming you run Ubuntu/opencv_latest.sh which in turn calls opencv_install.sh and then dependencies.sh, there are some apt-get install calls, so you''ll end up having pre-built Qt libraries along with your cross-compiled ones...

    function install_dependency {
        echo "--- Installing dependency: $1"
        sudo apt-get -y install $1
    }
    ...
    install_dependency libqt5x11extras5
    install_dependency libqt5opengl5
    install_dependency libqt5opengl5-dev
    

    So may I suggest to start from scratch?

    First I'd follow the mechatronics guide to cross-compile and deploy Qt in the RPi device.

    Then I'd follow this guide to cross compile the latest version of OpenCV for Raspberry Pi. As you'll use WITH_QT=ON flag I guess, please adjust the paths in the CMake script(s) to use the cross-compiled Qt version in your host PC.

    And also use the correct path for cross-compiled OpenCV in your .pro file. As example, the following doesn't look good to me:

    LIBS += -L/usr/local/lib/libopencv_highgui.so