Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29235 Discussions

Conceptual question on DLL's and their import libraries

Jon_D
New Contributor II
665 Views

I just finished a task that inluded linking a CVF-created DLL to a Lahey Fortran executable. During the process and after reading LF and CVF documentation on using DLL's I ended up with the following question(s):

Both compilers' documentations suggest that the import library created during the compilation of DLL should beincluded during thecompilation ofa consoleexecutable that uses the DLL. I tested this withCVF. Sure enough, if theDLL's import library is not included in the executable's project you end up with a linker error. On the other hand, Lahey didn't complain about not having the import library; referencing the DLL during the compilation of the console executable was enough. Similarly with Visual Basic one doesn't need the import library when linking the VB code against a Fortran DLL. So, my questions are, what is the the cause of this difference between two different programming languages and between two compilers for the same language? Why can one Fortran compiler (LF) link against a DLL without its import library (even if it is explained otherwise in its documentation) when the other one (CVF) can't? And ultimately, what are the mechanics of linking a console executable against a DLL (i.e. what information is stored in the .dll and .lib files and how is this informationutilized during linking)

I appreciate any clarifications on this.

John

0 Kudos
2 Replies
Nick2
New Contributor I
665 Views

without the .lib file, your application has to find the dll, load the dll, search the dll for a function corresponding to the one you want - all at run-time.

with the .lib file, your compiler will have a pretty good idea of what the dll looks like, before run-time. this has the advantage that if you try to call a function whatever(), the linker will tell you whether or not you're doing it correctly. if you're not calling it correctly, your app fails at link time. if you don't use a lib file, and you're not doing the function call correctly, then your app fails at runtime.

0 Kudos
Jon_D
New Contributor II
665 Views

Thanks! This makes sense. Are the .lib files universal or compiler dependent? I mean, will LF read the .lib file created by CVF and vise versa? And can Visual Basic read the .lib file CVF generates (I don't know if this is even an option for VB, though)?

John

0 Kudos
Reply