Search code examples
c++opencvclion

Why my "Reso"(resources) file is not recognized in Clion while trying to run OpenCV?


I'm trying to run a single program that opens a image file in Clion C++:

See image:

enter image description here

As you can see here, i have a file named "Reso" and a image named "test.png", but this code always will promt "Error reading image"

NOTE: I have proven that this does work in Visual Studio perfectly, but for some reason the file is not recognized in Clion


Solution

  • When you run a binary in CLion, your application will have by default the current working directory set to where your binary is located, which is probably somewhere in your cmake-build-debug directory.

    In your case you expect a certain directory, because your resource file is somehwere else. You can either change your code to allow passing the path by argument, or you can set the working directory in CLion for your binary.

    In the top you have this bar, where you can choose your build target. There is an option Edit configurations and when you open this and select your target, you can see a field Working directory. Set this field appropriate for your project.