Reputation: 1965
When running an opencv project, some of the dll are needed to be either in the exe path, or in the computer's path.
EDIT: when creating an opencv project, I add the .lib files in the linker properties. When executing, the exe searches for the corresponding dll files. My question is where in the opencv source code (I guess the source code of the .lib files) is the line that loads the dll files.
Thanks
Ohad
Upvotes: 0
Views: 445
Reputation: 3047
OpenCV's dll files are loaded immediately on execution. You can easily test that by having a simple program that only does a System("PAUSE");
Even a simple program will not run if the required opencv dll files are not present.
The difference from static linking is that if you link statically, the library will be inserted inside your executable and you do not need to distribute any opencv library files with your software.
Upvotes: 0
Reputation: 2247
1.at what time the dll are loaded (static time?)
The 'd' in 'dll' stands for 'dynamic'. So this means a dll is loaded at runtime, definitely not at 'static time'.
2.where in the opencv source code the dll are loaded? searching for "loadLibrary" in the opencv source gave zero results...
That would be the dynamic linker/loader. Now I haven't written anything for Windows in a long time, so I'm unsure whether dlls are loaded lazily or not. In any case, when you build your project (.exe or .dll, it does not matter), the compiler will embed a notice akin to "Oh by the way, I need to use opencv.dll" in your final .exe or .dll.
Therefore when you run your .exe (or when your .dll gets loaded by another program), the loader will see this notice and look for an opencv.dll somewhere (i.e. in the current directory or any directory listed in your PATH environment variable).
It's all done without you or anyone having to call anything like loadLibrary
. Because you've explicitely told your compiler that your program has a dependency on opencv.dll, and because compilers tend to be nice with developers, it will generate the necessary code (as in "machine code", in your .exe or .dll) to load the library for you.
loadLibrary
is mainly used when you don't want your program to be explicitely dependent on a given dll (i.e. you still want your program to work if the dll is not accessible), but you would like to load it as a module if it is available. Think about plugins that extend functionalities to your core program.
Upvotes: 3