I can’t seem to get opencv to work with g++/premake5. Include files work of course, but I try to link the opencv world lib to either g++ and premake5, but i just get an undefined reference error.
More specifically, I’m simply trying to make a cv::Mat object and I get undefined reference to cv::Mat::Mat() and cv::Mat::~Mat().
What can I do to resolve this? CMake is a pain to use so I’m trying to avoid that.
Sorry, I guess I should have included that info first.
System Info
I am using Windows 10. My compiler is g++ 8.1.0 (installed using MinGW I believe, it’s been a while). OpenCV version 4.5.4 (latest I could find yesterday). My build system is premake5 version 5.0.0-alpha16.
Code Info
Directory Structure (before running premake5):
main.cpp
premake5.lua
Directory Structure (after running premake5 gmake2 and mingw32-make):
main.cpp
premake5.lua
Makefile
opencv-first.make
bin/
obj/
(last two just store object and binary files)
main.cpp
#include <opencv2/opencv.hpp>
#include <iostream>
int main() {
cv::Mat img;
}
premake5.lua (setup build system)
I tried putting in the only lib files I saw, opencv_world454 and opencv_world454d.
well, bad news is: you cannot use the prebuilt libs from the winpack,
those are for msvc only (that’s why it refuses to link)
means, you have to build the opencv libs from src, using cmake (hate it or not)
then, later, to build your own project, you can use, whatever ide / tools you like.
So basically, I need to use CMake to make my own lib files? Do the include files get generated in the process? (I checked the opencv source files, and include only has opencv.hpp) What if I use the linux build (lol), as they are built with make in mind? I’m guessing they make kernel calls that aren’t supported in windows.
Alright, I’ve run CMake and mingw32-make and mingw32-make install. The include files get generated and I get a bunch of lib files generated. However, when I try to link the files to premake5 (using same configuration as above, except with new libs), I still get undefined reference to cv::Mat::Mat() error (exact same as above).
Lol I was just using the wrong lib name. I should not have included the .dll part of the name. OpenCV seems to work now. Next step will be figuring out how to not use DLLs. Thanks for all your help!
again, it follows gcc convention, if you’re using mingw, like -lopencv_core454
did you mean: building & linking static libs ?
there’s a BUILD_SHARED_LIBS=OFF cmake flag for this.
however, note, that linking your project later will be much more difficult, as you have to order the libs you link to by dependancy, and have to manually add all system libs used
or maybe stay with dyamic and use a single “world” lib (like in your initial try) , BUILD_opencv_world=ON would do that.