+ 1
Dynamic library lib file
Hi I have created dll and it generates one dll file and one lib file.. If I am creating an executable attaching the lib file, is it sufficient to avoid dynamic library load calls?
8 Réponses
+ 3
If you link your executable with the import library (.lib) generated alongside the DLL, you're essentially statically linking against the DLL, which means you're incorporating the code from the DLL directly into your executable at compile time. In this scenario, you lose the dynamic behavior of loading the DLL at runtime.
So, if you modify the code of the DLL and rebuild it, those changes won't be reflected in your executable unless you recompile your executable against the updated import library generated with the new version of the DLL.
+ 3
If you are linking your executable with the .lib file generated alongside your DLL, it should be sufficient to avoid dynamic library load calls at runtime. Because the linker will include the necessary code from the DLL directly into your executable during the linking process.
+ 3
Yes. If you're okay with dynamically loading the DLL as needed during runtime, then you don't necessarily need to link against the import library (.lib) during the compilation of your executable. Dynamic loading allows you to load DLLs at runtime.
+ 2
And one more point. If I am linking lib generated with dll and not doing dll loading, I don't get my dynamic behaviour. Right ? In other words, if I modify the code of dll and just build it will not be sufficient to have those changes available in exe unless I again link lib generated with dll with exe.
Doing so avoid advantage and hence I am not getting point of generating dll and then linking lib file with exe. Is there other use case where this helps?
+ 2
Yes, it can often make more sense to use a static library rather than generating a DLL when you're linking against the import library (.lib) with your executable. The use of an import library with an executable essentially provides static linking behavior, where the code from the DLL is incorporated directly into the executable at compile time. In such cases, the benefits typically associated with DLLs, such as dynamic loading and runtime flexibility, are not fully realized. If dynamic loading is not a requirement, using a static library can offer a simpler and more straightforward solution.
+ 2
Yes, if you link your executable with the generated lib file, it will statically link the DLL's functionality into the executable. This means you won't need dynamic loading calls during runtime since everything will be contained within the executable itself.
+ 1
Thanks. If I am ok to do dynamic loading of dll as my need arises, then linking of lib is not needed. Is this correct ?
0
One last point. I don't need to link imp library .lib generated with dll but it is must to be present beside the dll.
So, lib contains all the details like static library scenario. Dll is just the way to lazily load at the time of requirement rather than linking initially. So, does it make sense to generate dll when we are linking imp lib with exe ? Does not it be a better choice to make static library instead of dll here?