'OpenCV C++, Does not run anything when a class/function defined in opnecv

I am facing a rather strange issue. This is the first time I am using OpenCV with C++ and I was trying to do just basic image reading and grayscaling it.

When I run the below code, everything's fine, it prints from 0 to 9:

#include <iostream>

int main() {

   for (int i = 0; i < 10; i++)
       std::cout << i << std::endl;
   
   return 0;
}

However, when I include opencv2 and try to use something related to it, I might not print, output, or display anything. The below code still works:

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

using namespace cv;

int main() {

    for (int i = 0; i < 10; i++)
        std::cout << i << std::endl;
    std::cout << "OpenCV version : " << CV_VERSION << std::endl;
    return 0;
}

But when I add a new line for reading an image, it just does nothing. It does not print the numbers or the CV version:

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

using namespace cv;

int main() {

    for (int i = 0; i < 10; i++)
        std::cout << i << std::endl;
    std::cout << "OpenCV version : " << CV_VERSION << std::endl;
    Mat img = imread("someimage.jpg");
    return 0;
}

I would appreciate any help, thanks in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source