Unable to link opencv library to QT Creator
-
Hello everybody,
I am new to QT, and I am trying to build a desktop application.
My setup:
1, QT Creator
2, QT Version 6.6.0
3, MingGW 64 bit
4, opencv 4.5.0
5, QmakeI installed opencv using the windows installer from the official website.
I set up the library using the Add Library dialog box(I right clicked on the project to see the option). After the library was added, the following code was added to the .pro file of my project.win32:CONFIG(release, debug|release): LIBS += -L$$PWD/'../AI EDA/opencv/build/x64/vc14/lib/' -lopencv_world450 else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/'../AI EDA/opencv/build/x64/vc14/lib/' -lopencv_world450d INCLUDEPATH += $$PWD/'../AI EDA/opencv/build/include' DEPENDPATH += $$PWD/'../AI EDA/opencv/build/include'
I thought I set up everything well, but I am getting the following errors.
C:\Users\ibrvy\OneDrive\Documents\Inventory_and_Billing\signin.cpp:30: error: undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)' :-1: error: debug/signin.o: in function `cv::Mat::~Mat()': C:\Users\ibrvy\OneDrive\Documents\AI EDA\opencv\build\include\opencv2\core\mat.inl.hpp:751: error: undefined reference to `cv::fastFree(void*)' :-1: error: debug/signin.o: in function `cv::Mat::release()': C:\Users\ibrvy\OneDrive\Documents\AI EDA\opencv\build\include\opencv2\core\mat.inl.hpp:863: error: undefined reference to `cv::Mat::deallocate()' :-1: error: collect2.exe: error: ld returned 1 exit status :-1: error: [Makefile.Debug:99: debug/Inventory_and_Billing.exe] Error 1
This is the code which has the opencv functions, This code is in a constructor of a class, which object is created in the main.cpp. And I am including the headers as well
#include "opencv2/opencv.hpp"using namespace cv; std::string path="C:/Users/ibrvy/OneDrive/Pictures/Video Projects/MISSING VALS.png"; Mat img=imread(path); imshow("Image",img);
I previusly tried with opencv 4.8.0 but I couldn't get it working.
what am I doing wrong ??? -
Hello everybody,
I am new to QT, and I am trying to build a desktop application.
My setup:
1, QT Creator
2, QT Version 6.6.0
3, MingGW 64 bit
4, opencv 4.5.0
5, QmakeI installed opencv using the windows installer from the official website.
I set up the library using the Add Library dialog box(I right clicked on the project to see the option). After the library was added, the following code was added to the .pro file of my project.win32:CONFIG(release, debug|release): LIBS += -L$$PWD/'../AI EDA/opencv/build/x64/vc14/lib/' -lopencv_world450 else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/'../AI EDA/opencv/build/x64/vc14/lib/' -lopencv_world450d INCLUDEPATH += $$PWD/'../AI EDA/opencv/build/include' DEPENDPATH += $$PWD/'../AI EDA/opencv/build/include'
I thought I set up everything well, but I am getting the following errors.
C:\Users\ibrvy\OneDrive\Documents\Inventory_and_Billing\signin.cpp:30: error: undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)' :-1: error: debug/signin.o: in function `cv::Mat::~Mat()': C:\Users\ibrvy\OneDrive\Documents\AI EDA\opencv\build\include\opencv2\core\mat.inl.hpp:751: error: undefined reference to `cv::fastFree(void*)' :-1: error: debug/signin.o: in function `cv::Mat::release()': C:\Users\ibrvy\OneDrive\Documents\AI EDA\opencv\build\include\opencv2\core\mat.inl.hpp:863: error: undefined reference to `cv::Mat::deallocate()' :-1: error: collect2.exe: error: ld returned 1 exit status :-1: error: [Makefile.Debug:99: debug/Inventory_and_Billing.exe] Error 1
This is the code which has the opencv functions, This code is in a constructor of a class, which object is created in the main.cpp. And I am including the headers as well
#include "opencv2/opencv.hpp"using namespace cv; std::string path="C:/Users/ibrvy/OneDrive/Pictures/Video Projects/MISSING VALS.png"; Mat img=imread(path); imshow("Image",img);
I previusly tried with opencv 4.8.0 but I couldn't get it working.
what am I doing wrong ???@vibelin
These are linker errors, not compilation ones. I am not an expert, but Google for the error messages likeerror: undefined reference to
cv::fastFree(void*)`. There are several people reporting this and several suggestions. For example, one answer sayswhat are you linking ?
-lopencv_imgcodecs
is needed forimread()
I'm not sure what you will need now and for MinGW, but I suspect you are still missing some
-l...
for the undefined references. -
Hello everybody,
I am new to QT, and I am trying to build a desktop application.
My setup:
1, QT Creator
2, QT Version 6.6.0
3, MingGW 64 bit
4, opencv 4.5.0
5, QmakeI installed opencv using the windows installer from the official website.
I set up the library using the Add Library dialog box(I right clicked on the project to see the option). After the library was added, the following code was added to the .pro file of my project.win32:CONFIG(release, debug|release): LIBS += -L$$PWD/'../AI EDA/opencv/build/x64/vc14/lib/' -lopencv_world450 else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/'../AI EDA/opencv/build/x64/vc14/lib/' -lopencv_world450d INCLUDEPATH += $$PWD/'../AI EDA/opencv/build/include' DEPENDPATH += $$PWD/'../AI EDA/opencv/build/include'
I thought I set up everything well, but I am getting the following errors.
C:\Users\ibrvy\OneDrive\Documents\Inventory_and_Billing\signin.cpp:30: error: undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)' :-1: error: debug/signin.o: in function `cv::Mat::~Mat()': C:\Users\ibrvy\OneDrive\Documents\AI EDA\opencv\build\include\opencv2\core\mat.inl.hpp:751: error: undefined reference to `cv::fastFree(void*)' :-1: error: debug/signin.o: in function `cv::Mat::release()': C:\Users\ibrvy\OneDrive\Documents\AI EDA\opencv\build\include\opencv2\core\mat.inl.hpp:863: error: undefined reference to `cv::Mat::deallocate()' :-1: error: collect2.exe: error: ld returned 1 exit status :-1: error: [Makefile.Debug:99: debug/Inventory_and_Billing.exe] Error 1
This is the code which has the opencv functions, This code is in a constructor of a class, which object is created in the main.cpp. And I am including the headers as well
#include "opencv2/opencv.hpp"using namespace cv; std::string path="C:/Users/ibrvy/OneDrive/Pictures/Video Projects/MISSING VALS.png"; Mat img=imread(path); imshow("Image",img);
I previusly tried with opencv 4.8.0 but I couldn't get it working.
what am I doing wrong ???@vibelin said in Unable to link opencv library to QT Creator:
EDA/opencv/build/x64/vc14/lib/' -lopencv_world450
You are using the VC version with MinGW.
@JonB The
opencv_world
includes everything, but therefore it's pretty huge and packed with modules you would never use.
So usually you would link + include only those you are acutally using in your project.
But it's not wrong to use it :) -
@vibelin
These are linker errors, not compilation ones. I am not an expert, but Google for the error messages likeerror: undefined reference to
cv::fastFree(void*)`. There are several people reporting this and several suggestions. For example, one answer sayswhat are you linking ?
-lopencv_imgcodecs
is needed forimread()
I'm not sure what you will need now and for MinGW, but I suspect you are still missing some
-l...
for the undefined references.@JonB
I already tried most of the solutions available, I even tried the particular solution you have mentioned. This is the error I get when i add 'lopencv_imgcodecs' to the LIBS: statement in my .pro file, Some solutions online suggested using the 'lopencv_imgcodecs450'. I still get the same error:-1: error: cannot find -lopencv_imgcodecs450
-
@vibelin said in Unable to link opencv library to QT Creator:
EDA/opencv/build/x64/vc14/lib/' -lopencv_world450
You are using the VC version with MinGW.
@JonB The
opencv_world
includes everything, but therefore it's pretty huge and packed with modules you would never use.
So usually you would link + include only those you are acutally using in your project.
But it's not wrong to use it :)