Why after linking the OpenCV libraries, Mat objects are still 'undefined'?
-
Call "file /usr/local/lib/libopencv_core.so". What do you get ?
As for your .pro file:
LIBS += -L/usr/local/lib \ -lopencv_core \ -lopencv_highgui \ -lopencv_imgproc
should be enough to link to these OpenCV libraries.
-
@SGaist It was a 'symbolic link' to libopencv_imgproc.so.4.5.0, so I called it again for that and got:
file /usr/local/lib/libopencv_imgproc.so.4.5.0
/usr/local/lib/libopencv_imgproc.so.4.5.0: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=a9e4463d8bcc7f5051819e1ab34a131be7685cb3, not stripped -
Can you show your current .pro file content ?
-
@SGaist yes :
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgetsCONFIG += c++11 # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ core.cpp \ main.cpp \ mainwindow.cpp HEADERS += \ mainwindow.h FORMS += \ mainwindow.ui INCLUDEPATH += -I/usr/local/include LIBS += -L/usr/local/lib \ -lopencv_core \ -lopencv_highgui \ -lopencv_imgproc # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target
-
That looks good. What exact error are you getting now, after doing a full rebuild ?
-
That's not a linking problem you have there.
Where is opencv2/core.hpp located exactly in your system ?
-
Did you notice the "opencv4" folder that is missing from your INCLUDEPATH statement ?
Either add it there or to your include statements.
-
Please provide the information directly.
What exactly did you try ?
What is the error your get ? -
@SGaist said in Why after linking the OpenCV libraries, Mat objects are still 'undefined'?:
Did you notice the "opencv4" folder that is missing from your INCLUDEPATH statement ?
Either add it there or to your include statements.
I wrote "either" which means one or the other, not both.
-
So I changed it in the main.cpp file because otherwise I got those errors . Now in the .pro file is /usr/local/include.
I still get the same errors
The last error I don't understand because I wrote opencv2/core/core.hpp not opencv2/core.hpp and I cleaned the project again before
-
So I changed it in the main.cpp file because otherwise I got those errors . Now in the .pro file is /usr/local/include.
I still get the same errors
The last error I don't understand because I wrote opencv2/core/core.hpp not opencv2/core.hpp and I cleaned the project again before
-
@georgiav Change INCLUDEPATH in your pro file so, that it points to /usr/local/include/opencv4 and change your includes like
#include "opencv2/...
-
Here is a minimal example adjusted to the paths you shown to us:
.pro file:
TEMPLATE = app TARGET = test_opencv INCLUDEPATH += . INCLUDEPATH += /usr/local/include/opencv4 LIBS += -L/usr/local/lib/ -lopencv_core SOURCES += main.cpp
main.cpp:
#include <opencv2/core.hpp> int main(int argc, char **argv) { cv::Mat mat; return 0; }
-
Here is a minimal example adjusted to the paths you shown to us:
.pro file:
TEMPLATE = app TARGET = test_opencv INCLUDEPATH += . INCLUDEPATH += /usr/local/include/opencv4 LIBS += -L/usr/local/lib/ -lopencv_core SOURCES += main.cpp
main.cpp:
#include <opencv2/core.hpp> int main(int argc, char **argv) { cv::Mat mat; return 0; }
-
@georgiav said in Why after linking the OpenCV libraries, Mat objects are still 'undefined'?:
this seems to work fine!
so please don't forget to mark your post as solved!
-