问题
I have built VTK in my computer with both dll and .lib files. When I want to create a project that uses VTK, I have to include the header files and link .lib files in project properties. In addition I have to add the .dll files in to the project path as well. I have several questions regarding this,
- What is the difference between .libs and .dll files?
- Is it possible to create a project with only using either .dll or .lib files. (I can link the .lib files and not add dlls to path or add dlls to path and not link .lib files)?
I would be grateful for any explanations. Thanks.
回答1:
.lib files are used by the linker to resolve imported items. .dll files contain code that is loaded dynamically at runtime.
If you have a static library, it contains all the code needed and there is no .dll. If you have a .dll you also need the companion .lib for linking correctly.
回答2:
The .lib files are only used by the linker during compilation. Whereas .dll files are used by the compiled exe during execution. In other words, after you've compiled the program you shouldn't need the .lib files anymore. When packaging your software for distribution you will only need your .exe, the .dll's, and any resources that didn't get packaged into your exe.
来源:https://stackoverflow.com/questions/34390997/static-lib-vs-dll-in-visual-studio