locked
.dll vs. .lib RRS feed

  • Question

  • ok
    when install a sdk ie. DirectX or OpenGL
    .dll go in system32 folder
    .lib go in vc->lib folder
    and
    .h go in vc->include folder

    I think i understand why the .dll go in the system32 folder. this is so you can run your prodject on your machine because this is where windows will look for the libraries.
    I guess my question is why does the IDE need the .lib if I am "#include ****.h;" in the source code.
    Friday, October 16, 2009 1:04 AM

Answers

  • The .lib file tells the linker (last stage of the compilation of your application) where to find, inside the DLL, the items declared in the .H file.

    Without this, the program wouldn't know how to use the DLL.



    Reed Copsey, Jr. - http://reedcopsey.com
    Friday, October 16, 2009 1:21 AM
  • This .lib file is the import library file, generally, it contains the name of the DLL and a table of the exported functions' entries.  Without this .lib file, we often see the link error "unresolved symbol".
    ".lib + .h" is the way of Load-time dynamic linking.

    We could also use the DLL without this import library file(.lib), that's called--Run-time dynamic linking.
    We call either the LoadLibrary function or the LoadLibraryEx function to load the DLL at run time in our application.  After the DLL is successfully loaded, we obtain the address of the exported DLL functions use the GetProcAddress function, then call them in our application.  Using run-time dynamic linking, we do not need an import library file.

    Sincerely,
    Wesley
    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Wesley Yao Monday, October 19, 2009 3:55 AM
    Monday, October 19, 2009 3:54 AM

All replies

  • The .lib file tells the linker (last stage of the compilation of your application) where to find, inside the DLL, the items declared in the .H file.

    Without this, the program wouldn't know how to use the DLL.



    Reed Copsey, Jr. - http://reedcopsey.com
    Friday, October 16, 2009 1:21 AM
  • This .lib file is the import library file, generally, it contains the name of the DLL and a table of the exported functions' entries.  Without this .lib file, we often see the link error "unresolved symbol".
    ".lib + .h" is the way of Load-time dynamic linking.

    We could also use the DLL without this import library file(.lib), that's called--Run-time dynamic linking.
    We call either the LoadLibrary function or the LoadLibraryEx function to load the DLL at run time in our application.  After the DLL is successfully loaded, we obtain the address of the exported DLL functions use the GetProcAddress function, then call them in our application.  Using run-time dynamic linking, we do not need an import library file.

    Sincerely,
    Wesley
    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Wesley Yao Monday, October 19, 2009 3:55 AM
    Monday, October 19, 2009 3:54 AM