Cross compile OpenCV to a RaspberryPI
-
@jsulm May i ask how do i sync my sysroot exactly because i've already installed OpenCV in my RaspberryPi
@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.
-
@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.
@jsulm do i need to install OpenCV On the host machine as well ?
-
@jsulm do i need to install OpenCV On the host machine as well ?
@hamzaelazizi No, why should you if you want to cross compile? Host libraries have nothing to do with RaspberryPi.
-
@hamzaelazizi No, why should you if you want to cross compile? Host libraries have nothing to do with RaspberryPi.
@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 "
-
@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 "
@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 -
@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@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
-
@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
@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) -
@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)@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" -
@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"@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 commandfind / -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. -
@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 commandfind / -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.@JonB in case i was able to find its location, how can i tell Qt Creator to look for that library in that path ?
-
@JonB in case i was able to find its location, how can i tell Qt Creator to look for that library in that path ?
@hamzaelazizi
I have updated my post to give you a Linuxfind
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.... -
@hamzaelazizi
I have updated my post to give you a Linuxfind
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....@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.ai used the one with the Bold writing
-
@hamzaelazizi
I have updated my post to give you a Linuxfind
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....@JonB after i included the one i told you about i started having other errors :
undefined reference to cv::imshow
undefined reference tocv::imread undefined reference to
cv::wait
undefined reference to `cv::Mat -
@JonB after i included the one i told you about i started having other errors :
undefined reference to cv::imshow
undefined reference tocv::imread undefined reference to
cv::wait
undefined reference to `cv::Mat -
@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....@JonB Okey i'll be waiting for him to reply back, hopefully he does
-
@JonB Okey i'll be waiting for him to reply back, hopefully he does
@hamzaelazizi Try this (add it to your pro file):
LIBS += -L/usr/lib/arm-linux-gnueabihf -lm
-
@hamzaelazizi Try this (add it to your pro file):
LIBS += -L/usr/lib/arm-linux-gnueabihf -lm
@jsulm yes i changed the path to the one i have and it worked but it then started showing these different errors :
undefined reference to cv::imshow
undefined reference to cv::imread
undefined reference to cv::wait
undefined reference to cv::Mat -
here's my .pro file code :
TEMPLATE = app CONFIG += console c++11 CONFIG -= app_bundle CONFIG -= qt INCLUDEPATH += /home/rnsaoberon/rpi-qt/sysroot/usr/local/include/opencv4 #DEPENDPATH += /home/rnsaoberon/rpi-qt/sysroot/usr/local/include/opencv4 QT_CONFIG -= no-pkg-config LIBS += `pkg-config --cflags --libs opencv4` LIBS += -L/home/rnsaoberon/rpi-qt/sysroot/usr/lib/arm-linux-gnueabihf -lm #CONFIG += link_pkgconfig #PKGCONFIG += opencv4 SOURCES += \ main.cpp # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /home/pi/$${TARGET} !isEmpty(target.path): INSTALLS += target
and here's my main c++ code :
#include <opencv2/highgui.hpp> int main() { cv::Mat img = cv::imread("/home/pi/Pictures/drake.jpg"); cv::imshow("Window",img); cv::waitKey(0); return 0; }
-
here's my .pro file code :
TEMPLATE = app CONFIG += console c++11 CONFIG -= app_bundle CONFIG -= qt INCLUDEPATH += /home/rnsaoberon/rpi-qt/sysroot/usr/local/include/opencv4 #DEPENDPATH += /home/rnsaoberon/rpi-qt/sysroot/usr/local/include/opencv4 QT_CONFIG -= no-pkg-config LIBS += `pkg-config --cflags --libs opencv4` LIBS += -L/home/rnsaoberon/rpi-qt/sysroot/usr/lib/arm-linux-gnueabihf -lm #CONFIG += link_pkgconfig #PKGCONFIG += opencv4 SOURCES += \ main.cpp # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /home/pi/$${TARGET} !isEmpty(target.path): INSTALLS += target
and here's my main c++ code :
#include <opencv2/highgui.hpp> int main() { cv::Mat img = cv::imread("/home/pi/Pictures/drake.jpg"); cv::imshow("Window",img); cv::waitKey(0); return 0; }
@hamzaelazizi said in Cross compile OpenCV to a RaspberryPI:
LIBS += -L/home/rnsaoberon/rpi-qt/sysroot/usr/lib/arm-linux-gnueabihf -lm
While you await @jsulm who actually knows something about this...!
I believe you are saying:
- without
-L/home/rnsaoberon/rpi-qt/sysroot/usr/lib/arm-linux-gnueabihf
, although it cannot find the-lm
library, you do not get errorsundefined reference to cv::...
, right? - with
-L/home/rnsaoberon/rpi-qt/sysroot/usr/lib/arm-linux-gnueabihf
, it finds the math library, but you do get errorsundefined reference to cv::...
, right?
In that case, by putting
/home/rnsaoberon/rpi-qt/sysroot/usr/lib/arm-linux-gnueabihf
high on the library directory search list thecv::...
stuff it also needs is no longer found, because it must find some differentcv
library archives (in that specified directory) instead of what it used to find, and those libraries do not include something which would resolve those references.What you do/are supposed to do with that I do not know.....
UPDATE
Oh, maybe not. Those "undefined"s may always have been there. But when it cannot resolve the-lm
on the link line it will stop there and won't get as far as the final step of linkage where it would notice undefineds. So the-L/home/rnsaoberon/rpi-qt/sysroot/usr/lib/arm-linux-gnueabihf
may be nothing to do with the "undefined"s....You might start by running
pkg-config --cflags --libs opencv4
in a terminal, to at least see what that is producing. E.g. if that is not even outputting any library paths to put into yourLIBS
it's not right.... - without
-
here's my .pro file code :
TEMPLATE = app CONFIG += console c++11 CONFIG -= app_bundle CONFIG -= qt INCLUDEPATH += /home/rnsaoberon/rpi-qt/sysroot/usr/local/include/opencv4 #DEPENDPATH += /home/rnsaoberon/rpi-qt/sysroot/usr/local/include/opencv4 QT_CONFIG -= no-pkg-config LIBS += `pkg-config --cflags --libs opencv4` LIBS += -L/home/rnsaoberon/rpi-qt/sysroot/usr/lib/arm-linux-gnueabihf -lm #CONFIG += link_pkgconfig #PKGCONFIG += opencv4 SOURCES += \ main.cpp # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /home/pi/$${TARGET} !isEmpty(target.path): INSTALLS += target
and here's my main c++ code :
#include <opencv2/highgui.hpp> int main() { cv::Mat img = cv::imread("/home/pi/Pictures/drake.jpg"); cv::imshow("Window",img); cv::waitKey(0); return 0; }
@hamzaelazizi said in Cross compile OpenCV to a RaspberryPI:
INCLUDEPATH += /home/rnsaoberon/rpi-qt/sysroot/usr/local/include/opencv4
Please change all these paths!
You do NOT have to put the path of your sysroot!
It should look like this:INCLUDEPATH += /usr/local/include/opencv4
Also, why /usr/local?! I doubt OpenCV packages from your OS install anything in /usr/local! Please fix this!
"LIBS += -L/home/rnsaoberon/rpi-qt/sysroot/usr/lib/arm-linux-gnueabihf -lm" - this is also not what I suggested! Why do you add sysroot path everywhere?
LIBS += -L/usr/lib/arm-linux-gnueabihf -lm
The errors you posted mean that OpenCV libs are not found. If you really install OpenCV using your OS packet manager on your RaspberryPi the libs should be somewhere in /usr/lib and it should be enough to add -lLIBNAME to pro file.