问题
As far as I know the .lib file is some sort of compiled file and of course the dll file contains all the functions in it anyway. Why can't I just do with the .lib file or just the .dll file? Why do the instructions tell me to get all three of them?
By the way, are openGL files not free anyway that we have a "freeGLut"??
回答1:
As far as I know the .lib file is some sort of compiled file and of course the dll file contains all the functions in it anyway.
No, it's not that simple.
A DLL is a executable binary, minus an startup entry point. The DLL exports some symbols, but those are featureless, only positions in the address space. A compiler can not deduce from a standard DLL (or SO) what signature each symbol has. For this it needs to be told the signatures in some way through an additional source. This is the header file (.h).
However to be actually usefull, the DLL must be loaded into the process upon execution. For this the executable needs to be augmented with additional information, namely what DLL(s) to load. Under Windows this is done using a stub library (.lib), that merely carries that DLL import information. On other OSs you link against the "DLL" by pointing the linker to that one.
Why can't I just do with the .lib file or just the .dll file?
Because the .lib doesn't contain actual code but only the information, to use a certain DLL. And because the Microsoft tools can't pull their dynamic linkage information from the target DLLs.
Why do the instructions tell me to get all three of them?
Because each file has a specific function, and you need all three of them to
- get the function signatures (.h)
- tell your executable to load a certain DLL (.lib)
- and get the actual library in form of a .dll
By the way, are openGL files not free anyway that we have a "freeGLut"?
GLUT is not part of OpenGL. It's a independently developed library. Also OpenGL itself is just a specification and there are no "the" OpenGL sources; there are only particular implementations, of which some are free.
回答2:
glut32.h
is the header file used during the compilation stageglut32.lib
is the library file used by the linker to resolve references to the functions and/or object provided by theglut32
library. When used with a DLL, the .lib file is often called an "import library" and instead of actual code it has information the linker uses to cause the executable to implicitly reference the functions in the DLL so the runtime loader will also load the DLL when the executable is loaded at runtime. Some toolchains provide a tool (usually calledimplib
) which can produce an import library using a DLL as input.glut32.dll
is the dynamic library used at runtime to provide the functions and objects at executable time.
Some tools (for example the GCC toolchain) can use the DLL directly in place of the .lib file - in effect providing its own implib
functionality. I'm not sure why Microsoft hasn't supported that in their tools.
回答3:
GLUT is an optional component. You don't need it if your program doesn't use it. But if you use it, you need glut.h
because your program #include
s it, and you need glut32.lib
because it's the import library that the linker uses to establish your executable's relationship with the DLL. You don't need glut32.dll
when you compile or link your program (since the import library serves that purpose), but you need it when you run your program because it contains the actual GLUT functions that your program is calling.
Freeglut is an open-source clone of the original GLUT, because the original GLUT is out-of-date and its license doesn't allow others to make changes to improve it.
来源:https://stackoverflow.com/questions/11552100/why-do-i-need-glut-h-glut32-lib-glut32-dll-all-to-compile-an-opengl-program