Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Cross compile OpenCV to a RaspberryPI
Forum Update on Monday, May 27th 2025

Cross compile OpenCV to a RaspberryPI

Scheduled Pinned Locked Moved Unsolved General and Desktop
27 Posts 4 Posters 3.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hamzaelazizi
    wrote on 10 May 2022, 12:37 last edited by
    #1

    Hello, i've been trying to make an application that combines Qt and OpenCV, and then deploy this application on a RaspberryPi.
    i managed to cross compile Qt to run applications i built on my host machine on the RaspberryPi but whenever i want to use OpenCV with it, i fail to get to work. The first time i had incompatible libraries with ARM (they were x86-64) and now when i installed ARM version of OpenCV i get this error in Qt Creator (cannot find -lm).
    Can u please tell me how to cross compile OpenCV as well ? Thank you

    J 1 Reply Last reply 11 May 2022, 06:25
    0
    • K Offline
      K Offline
      Kent-Dorfman
      wrote on 10 May 2022, 22:51 last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • H hamzaelazizi
        10 May 2022, 12:37

        Hello, i've been trying to make an application that combines Qt and OpenCV, and then deploy this application on a RaspberryPi.
        i managed to cross compile Qt to run applications i built on my host machine on the RaspberryPi but whenever i want to use OpenCV with it, i fail to get to work. The first time i had incompatible libraries with ARM (they were x86-64) and now when i installed ARM version of OpenCV i get this error in Qt Creator (cannot find -lm).
        Can u please tell me how to cross compile OpenCV as well ? Thank you

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 11 May 2022, 06:25 last edited by
        #3

        @hamzaelazizi said in Cross compile OpenCV to a RaspberryPI:

        Can u please tell me how to cross compile OpenCV as well ?

        Why don't you simply install OpenCV packages (including dev packages) on your RaspberryPi (using apt) and then symply sync your sysroot?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        H 1 Reply Last reply 11 May 2022, 06:51
        0
        • J jsulm
          11 May 2022, 06:25

          @hamzaelazizi said in Cross compile OpenCV to a RaspberryPI:

          Can u please tell me how to cross compile OpenCV as well ?

          Why don't you simply install OpenCV packages (including dev packages) on your RaspberryPi (using apt) and then symply sync your sysroot?

          H Offline
          H Offline
          hamzaelazizi
          wrote on 11 May 2022, 06:51 last edited by
          #4

          @jsulm May i ask how do i sync my sysroot exactly because i've already installed OpenCV in my RaspberryPi

          J 1 Reply Last reply 11 May 2022, 07:14
          0
          • H hamzaelazizi
            11 May 2022, 06:51

            @jsulm May i ask how do i sync my sysroot exactly because i've already installed OpenCV in my RaspberryPi

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 11 May 2022, 07:14 last edited by
            #5

            @hamzaelazizi Depends on how you created it. There are different ways. For example you can simply connect the SD card from your RaspberryPi to your development machine. Or you can copy the /usr content (at least lib and include subfolders) to your development machine.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            H 1 Reply Last reply 11 May 2022, 07:18
            0
            • J jsulm
              11 May 2022, 07:14

              @hamzaelazizi Depends on how you created it. There are different ways. For example you can simply connect the SD card from your RaspberryPi to your development machine. Or you can copy the /usr content (at least lib and include subfolders) to your development machine.

              H Offline
              H Offline
              hamzaelazizi
              wrote on 11 May 2022, 07:18 last edited by
              #6

              @jsulm do i need to install OpenCV On the host machine as well ?

              J 1 Reply Last reply 11 May 2022, 07:19
              0
              • H hamzaelazizi
                11 May 2022, 07:18

                @jsulm do i need to install OpenCV On the host machine as well ?

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 11 May 2022, 07:19 last edited by
                #7

                @hamzaelazizi No, why should you if you want to cross compile? Host libraries have nothing to do with RaspberryPi.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                H 1 Reply Last reply 11 May 2022, 07:35
                0
                • J jsulm
                  11 May 2022, 07:19

                  @hamzaelazizi No, why should you if you want to cross compile? Host libraries have nothing to do with RaspberryPi.

                  H Offline
                  H Offline
                  hamzaelazizi
                  wrote on 11 May 2022, 07:35 last edited by
                  #8

                  @jsulm then what path should i include in my .pro file ? i've created a small qt program on my host machine and i simply want to open an image and display it on the raspberry but i don't know what to include in my .pro file and when i compile it i get the error saying " :-1: error: cannot find -lm "

                  J 1 Reply Last reply 11 May 2022, 07:59
                  0
                  • H hamzaelazizi
                    11 May 2022, 07:35

                    @jsulm then what path should i include in my .pro file ? i've created a small qt program on my host machine and i simply want to open an image and display it on the raspberry but i don't know what to include in my .pro file and when i compile it i get the error saying " :-1: error: cannot find -lm "

                    J Offline
                    J Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 11 May 2022, 07:59 last edited by
                    #9

                    @hamzaelazizi said in Cross compile OpenCV to a RaspberryPI:

                    then what path should i include in my .pro file ?

                    The libraries you need I guess? Or what exactly are you asking?
                    In this case OpenCV libs you're using.
                    In QtCreator you should have a Kit for cross compilation where you set your cross compiled Qt and also path to your sysroot.
                    You need to understand the difference between compiling for host and cross compalation. If you compile for the host then libraries/headers installed on your host are used. But if you're doing cross compilation libraries and headers are taken from the sysroot.
                    You can find here information about QtCreator set-up for cross compilation: https://www.ics.com/blog/configuring-qt-creator-raspberry-pi

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    H 1 Reply Last reply 11 May 2022, 08:34
                    0
                    • J jsulm
                      11 May 2022, 07:59

                      @hamzaelazizi said in Cross compile OpenCV to a RaspberryPI:

                      then what path should i include in my .pro file ?

                      The libraries you need I guess? Or what exactly are you asking?
                      In this case OpenCV libs you're using.
                      In QtCreator you should have a Kit for cross compilation where you set your cross compiled Qt and also path to your sysroot.
                      You need to understand the difference between compiling for host and cross compalation. If you compile for the host then libraries/headers installed on your host are used. But if you're doing cross compilation libraries and headers are taken from the sysroot.
                      You can find here information about QtCreator set-up for cross compilation: https://www.ics.com/blog/configuring-qt-creator-raspberry-pi

                      H Offline
                      H Offline
                      hamzaelazizi
                      wrote on 11 May 2022, 08:34 last edited by
                      #10

                      @jsulm i copied my folders "lib" and "include" where most of my OpenCV libraries are from the raspberry to the sysroot folder on my host machine but when i try to compile it keeps saying ":-1: error: cannot find -lm" i don't know why ?? i know it's an issue related to the math library but i don't know why it says this

                      J 1 Reply Last reply 11 May 2022, 09:07
                      0
                      • H hamzaelazizi
                        11 May 2022, 08:34

                        @jsulm i copied my folders "lib" and "include" where most of my OpenCV libraries are from the raspberry to the sysroot folder on my host machine but when i try to compile it keeps saying ":-1: error: cannot find -lm" i don't know why ?? i know it's an issue related to the math library but i don't know why it says this

                        J Offline
                        J Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on 11 May 2022, 09:07 last edited by
                        #11

                        @hamzaelazizi How do you build?
                        Do you build in QtCreator?
                        How does your sysroot look like? Its structure should be: PATH_TO_SYSROOT/usr/* (* is lib and include)

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        H 1 Reply Last reply 11 May 2022, 09:14
                        0
                        • J jsulm
                          11 May 2022, 09:07

                          @hamzaelazizi How do you build?
                          Do you build in QtCreator?
                          How does your sysroot look like? Its structure should be: PATH_TO_SYSROOT/usr/* (* is lib and include)

                          H Offline
                          H Offline
                          hamzaelazizi
                          wrote on 11 May 2022, 09:14 last edited by
                          #12

                          @jsulm yes i build in Qt Creator
                          i didn't understand your second question but here is my sysroot path : "/home/rpi-qt/sysroot/* (* is lib and include and local)
                          local is the file i copied with the OpenCV libraries in
                          when i build and compile another project, it works and i can deploy the application on the Raspberry but when i try to do something with OpenCV it shows that error "cannot find -lm"

                          J 1 Reply Last reply 11 May 2022, 09:48
                          0
                          • H hamzaelazizi
                            11 May 2022, 09:14

                            @jsulm yes i build in Qt Creator
                            i didn't understand your second question but here is my sysroot path : "/home/rpi-qt/sysroot/* (* is lib and include and local)
                            local is the file i copied with the OpenCV libraries in
                            when i build and compile another project, it works and i can deploy the application on the Raspberry but when i try to do something with OpenCV it shows that error "cannot find -lm"

                            J Offline
                            J Offline
                            JonB
                            wrote on 11 May 2022, 09:48 last edited by JonB 5 Nov 2022, 09:50
                            #13

                            @hamzaelazizi said in Cross compile OpenCV to a RaspberryPI:

                            error "cannot find -lm"

                            It is looking for file libm.a. Probably because OpenCV needs the math library. On Ubuntu, for example, that is in /usr/lib/x86_64-linux-gnu/libm.a. I don't know where yours is/is supposed to be, in your cross-compilation situation. Linux command find / -name libm.a -print 2>/dev/null on whichever machine, and wherever you need to look down from where mine specifies /, should find it if present.

                            H 1 Reply Last reply 11 May 2022, 09:50
                            0
                            • J JonB
                              11 May 2022, 09:48

                              @hamzaelazizi said in Cross compile OpenCV to a RaspberryPI:

                              error "cannot find -lm"

                              It is looking for file libm.a. Probably because OpenCV needs the math library. On Ubuntu, for example, that is in /usr/lib/x86_64-linux-gnu/libm.a. I don't know where yours is/is supposed to be, in your cross-compilation situation. Linux command find / -name libm.a -print 2>/dev/null on whichever machine, and wherever you need to look down from where mine specifies /, should find it if present.

                              H Offline
                              H Offline
                              hamzaelazizi
                              wrote on 11 May 2022, 09:50 last edited by
                              #14

                              @JonB in case i was able to find its location, how can i tell Qt Creator to look for that library in that path ?

                              J 1 Reply Last reply 11 May 2022, 09:52
                              0
                              • H hamzaelazizi
                                11 May 2022, 09:50

                                @JonB in case i was able to find its location, how can i tell Qt Creator to look for that library in that path ?

                                J Offline
                                J Offline
                                JonB
                                wrote on 11 May 2022, 09:52 last edited by
                                #15

                                @hamzaelazizi
                                I have updated my post to give you a Linux find command to help you locate it.
                                Let's see where, if anywhere, it tells you it finds it before we know how to proceed.
                                I don't do cross-compilation so I don't know where you need to look or what to do about it when you find it, you may need @jsulm's help when you have told us where it is....

                                H 2 Replies Last reply 11 May 2022, 10:04
                                0
                                • J JonB
                                  11 May 2022, 09:52

                                  @hamzaelazizi
                                  I have updated my post to give you a Linux find command to help you locate it.
                                  Let's see where, if anywhere, it tells you it finds it before we know how to proceed.
                                  I don't do cross-compilation so I don't know where you need to look or what to do about it when you find it, you may need @jsulm's help when you have told us where it is....

                                  H Offline
                                  H Offline
                                  hamzaelazizi
                                  wrote on 11 May 2022, 10:04 last edited by
                                  #16

                                  @JonB it gave me all these locations:

                                  /home/rnsaoberon/rpi-qt/tools/cross-pi-gcc-8.3.0-2/arm-linux-gnueabihf/libc/usr/lib/libm.a
                                  /home/rnsaoberon/rpi-qt/sysroot/lib/arm-linux-gnueabihf/libm.a
                                  /home/rnsaoberon/rpi-qt/sysroot/usr/lib/arm-linux-gnueabihf/libm.a
                                  /usr/arm-linux-gnueabi/libhf/libm.a
                                  /usr/lib/x86_64-linux-gnu/libm.a
                                  /usr/arm-linux-gnueabihf/lib/libm.a

                                  i used the one with the Bold writing

                                  1 Reply Last reply
                                  0
                                  • J JonB
                                    11 May 2022, 09:52

                                    @hamzaelazizi
                                    I have updated my post to give you a Linux find command to help you locate it.
                                    Let's see where, if anywhere, it tells you it finds it before we know how to proceed.
                                    I don't do cross-compilation so I don't know where you need to look or what to do about it when you find it, you may need @jsulm's help when you have told us where it is....

                                    H Offline
                                    H Offline
                                    hamzaelazizi
                                    wrote on 11 May 2022, 10:19 last edited by
                                    #17

                                    @JonB after i included the one i told you about i started having other errors :

                                    undefined reference to cv::imshow
                                    undefined reference to cv::imread undefined reference to cv::wait
                                    undefined reference to `cv::Mat

                                    J 1 Reply Last reply 11 May 2022, 10:20
                                    0
                                    • H hamzaelazizi
                                      11 May 2022, 10:19

                                      @JonB after i included the one i told you about i started having other errors :

                                      undefined reference to cv::imshow
                                      undefined reference to cv::imread undefined reference to cv::wait
                                      undefined reference to `cv::Mat

                                      J Offline
                                      J Offline
                                      JonB
                                      wrote on 11 May 2022, 10:20 last edited by
                                      #18

                                      @hamzaelazizi
                                      As I said, since I know nothing about cross-compilation or RPi you will have to await a comment from e.g. @jsulm as to what you are supposed to do....

                                      H 1 Reply Last reply 11 May 2022, 10:29
                                      0
                                      • J JonB
                                        11 May 2022, 10:20

                                        @hamzaelazizi
                                        As I said, since I know nothing about cross-compilation or RPi you will have to await a comment from e.g. @jsulm as to what you are supposed to do....

                                        H Offline
                                        H Offline
                                        hamzaelazizi
                                        wrote on 11 May 2022, 10:29 last edited by
                                        #19

                                        @JonB Okey i'll be waiting for him to reply back, hopefully he does

                                        J 1 Reply Last reply 11 May 2022, 11:02
                                        0
                                        • H hamzaelazizi
                                          11 May 2022, 10:29

                                          @JonB Okey i'll be waiting for him to reply back, hopefully he does

                                          J Offline
                                          J Offline
                                          jsulm
                                          Lifetime Qt Champion
                                          wrote on 11 May 2022, 11:02 last edited by
                                          #20

                                          @hamzaelazizi Try this (add it to your pro file):

                                          LIBS += -L/usr/lib/arm-linux-gnueabihf -lm
                                          

                                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                                          H 1 Reply Last reply 11 May 2022, 11:08
                                          2

                                          10/27

                                          11 May 2022, 08:34

                                          topic:navigator.unread, 17
                                          • Login

                                          • Login or register to search.
                                          10 out of 27
                                          • First post
                                            10/27
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved