Unsolved Cross compile linker issues
-
I'm trying to cross compile my Qt application that uses OpenCV to a Raspberry Pi, but I keep getting linker errors, such as the following:
undefined reference to `cv::putText(cv::Mat&, std::string const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)'
I'm using these options in my .pro file:
INCLUDEPATH += ~/raspi/sysroot/usr/include/opencv2/ INCLUDEPATH += ~/raspi/sysroot/usr/include/ LIBS += -L~/raspi/sysroot/usr/lib/ LIBS += -lopencv_core LIBS += -lopencv_imgproc LIBS += -lopencv_highgui LIBS += -lopencv_ml LIBS += -lopencv_video LIBS += -lopencv_features2d LIBS += -lopencv_calib3d LIBS += -lopencv_objdetect LIBS += -lopencv_contrib LIBS += -lopencv_legacy LIBS += -lopencv_flann
I installed OpenCV on the Raspberry Pi via the package "libopencv-dev". I've updated my sysroot and everything, but I don't know what to do from here. I've also tried using pkg-config in my .pro file, but that also left me with errors.
-
@Lashc you should check the actual linker command line if the directories and files are correctly given.
-
@aha_1980 Here's the appropriate portion of the make command generated by Qt Creator:
-L/home/username/raspi/sysroot/usr/lib/arm-linux-gnueabihf -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
(where "username" is replaced by my actual username). The folder in this command is the one where the libraries are. -
@Lashc then you should check if these librsry files have the correct format (with
file
command) and if they contain the symbol you are missing. Maybe you have to add another library? -
@aha_1980 This is the result I got from looking at one of the library files, libopencv_core.so.2.4.9, using the "file command":
libopencv_core.so.2.4.9: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=2b27e4b60b293641d3c5a1afefa5cc5a87b30521, stripped
.This looks fine to me for a Raspberry Pi. However, when using the "nm" command to look for symbols, I get this:
nm: libopencv_core.so.2.4.9: no symbols
. I then looked in the static library version and found a bunch of symbols. So do I need to compile with the static libraries? And if so, how? -
@Lashc I think you need to use the
arm-linux-...-nm
command, because the lib is cross-compiled. -
@aha_1980 The OpenCV libraries were not cross compiled. They were installed natively on the Raspberry Pi through apt. If I use the "nm" command on the Raspberry Pi, I still get no symbols in the .so file but plenty in the .a file. I can natively compile C++ programs that use OpenCV on the Raspberry Pi.
-
@Lashc said in Cross compile linker issues:
I'm using these options in my .pro file:
INCLUDEPATH += ~/raspi/sysroot/usr/include/opencv2/
INCLUDEPATH += ~/raspi/sysroot/usr/include/
LIBS += -L~/raspi/sysroot/usr/lib/
LIBS += -lopencv_core
LIBS += -lopencv_imgproc
LIBS += -lopencv_highgui
LIBS += -lopencv_ml
LIBS += -lopencv_video
LIBS += -lopencv_features2d
LIBS += -lopencv_calib3d
LIBS += -lopencv_objdetect
LIBS += -lopencv_contrib
LIBS += -lopencv_legacy
LIBS += -lopencv_flannJust in case, when I was working to use Qt + OpenCV on Android, it turned out that the order of the OpenCV libraries was important. See this post as a guideline as it may also apply to you.