Why need to set the path for opencv_world4100d.dll

opencv_world4100d.dll not found

I download pre-compiled opencv.
And using the opencv in my project on windows
It always show “opencv_world4100d.dll not found”
Until I set the variable to windows env by hand.

Q1.
Why need to set opencv_world4100d.dll ?
Becuase other lib just find_package(XXX)
And then I can directly use.

Q2.
Does any method (automatically) to set the path for windows?
Not the interface operation.

notice the d suffix? that’s for debug builds. you build your application as release or debug, but then the linked library and the corresponding DLL have to match that.

I think you misunderstand

I don’t think so.
Because I donwload Releases - OpenCV
This is release version.

I try to use the release version and it also show opencv_world4100.dll not found.
Until I set the variable to windows env by hand.

And the cmake can’t solve my problem that search opencv_world4100.dll automatically
with these command.
I already assign the install path. find_package should be found these (include 、bin、lib、…)

set(OpenCV_DIR "./opencv")
find_package(OpenCV REQUIRED)

find_package locates libraries to be used at compile time. Because you are on Windows and have a shared library (opencv_world4100.dll) this will find opencv_world4100.lib.

At runtime your executable needs to be able to locate opencv_world4100.dll. If the location of this was baked into the executable then you would only be able to use the executable on machines where opencv_world4100.dll was in the same location as on your build machine.

There are two main ways I am aware of which enable your executable to find shared libraries at runtime on Windows

  1. storing it in the same folder as your executable, and
  2. adding the path containing it to the user/system path.
1 Like

I doubt that.

Windows LoadLibrary has a defined mechanism. among other places, it looks for DLLs in the current working directory, in the directory containing the executable, and in PATH… AFAIK.

I’ll rephrase. If the only way for an executable to locate a shared library was with a baked in path then…

Ah, my misunderstanding :slight_smile:

1 Like

maybe the method is good

  1. storing it in the same folder as your executable, and

But the method is bad. If I want to move the application to other machine, it will miss the location
2. adding the path containing it to the user/system path.