I am new to OpenCV, but i just cant get it to work and i am kinda desperate

I keep getting this error:

C:/Users/myuser/Desktop/URSS/main.cpp:6: undefined reference to cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)

I tried to search online, and tried different stuff, different tutorials, but nothing seems to work, if i cant find any solution here, i guess i will just give up on this project.

My code is this:

#include <iostream>
#include <opencv2/opencv.hpp>

int main(int argc, char** argv){
    auto filename = "C:/Users/myuser/Desktop/541957.png";
    auto image = cv::imread(filename);

    cv::imshow("Image", image);

    return 0;

you’re probably also new to c++, building peograms & all …

your linker is telling you, that it wants to use some function (cv::imread()) but it cannot find it’s implementation – , you’re not linking the correct library !!

depending on what you installed - either add opencv_imgcodecs480.lib or opencv_world480.lib (which contains all other opencv libs) to your “Additional Link Libraries”

Not sure what i am supposed to do, this is a screenshot of the lib folder and everything seems fine, maybe there is a problem cmakefile?

cmake_minimum_required(VERSION 3.0.0)

project(ScreenShare VERSION 0.1.0)



find_package(OpenCV REQUIRED)

find_package(Threads REQUIRED)

add_executable(executable main.cpp)







target_link_libraries(executable ${OpenCV_LIBS} ${CMAKE_THREAD_LIBS_INIT})

I am using this compiler

C:\Users\myuser>gcc --version
gcc (MinGW-W64 x86_64-msvcrt-posix-seh, built by Brecht Sanders) 13.0.1 20230122 (experimental)

Could this be the problem?

I copied this from a tutorial so i dont see why it shouldn’t work :pensive:
Again, sorry i am new to this

consider using Python

hah, problem spotted !

what you installed , only has libs for the VS compiler, you cannot use that with mingw

so, bad news is: you MUST build the opencv libs from src (resulting in *.a libs) before you can build your own program, using mingw (or change compiler → ~7gb dl)

(good news is, you already got the correct mingw version, there are plenty, which do not work AT ALL)

I think i got it… maybe