Pergunta

I've linked to glut32.lib and put glut32.dll in debug folder already

However, there still comes errors which I don't know what libraries they are linking to

solved external symbol __imp__glMaterialfv@12 referenced in function "void __cdecl copper_texture(void)" (?copper_texture@@YAXXZ)
1>rc.obj : error LNK2019: unresolved external symbol __imp__glVertex3f@12 referenced in function "void __cdecl do_display(void)" (?do_display@@YAXXZ)
1>rc.obj : error LNK2019: unresolved external symbol __imp__glNormal3f@12 referenced in function "void __cdecl do_display(void)" (?do_display@@YAXXZ)
1>rc.obj : error LNK2019: unresolved external symbol __imp__glEnd@0 referenced in function "void __cdecl do_display(void)" (?do_display@@YAXXZ)
1>rc.obj : error LNK2019: unresolved external symbol __imp__glVertex3fv@4 referenced in function "void __cdecl do_display(void)" (?do_display@@YAXXZ)
1>rc.obj : error LNK2019: unresolved external symbol __imp__glNormal3fv@4 referenced in function "void __cdecl do_display(void)" (?do_display@@YAXXZ)

As I may have tracked and found their definitions in GL.h like following:

WINGDIAPI void APIENTRY glVertex2sv (const GLshort *v);
WINGDIAPI void APIENTRY glVertex3d (GLdouble x, GLdouble y, GLdouble z);
WINGDIAPI void APIENTRY glVertex3dv (const GLdouble *v);
WINGDIAPI void APIENTRY glVertex3f (GLfloat x, GLfloat y, GLfloat z);
WINGDIAPI void APIENTRY glVertex3fv (const GLfloat *v);
WINGDIAPI void APIENTRY glVertex3i (GLint x, GLint y, GLint z);

How should I fix this linking problem?

Foi útil?

Solução

First, to clear up some major confusion you seem to be having, here's some information on what the stuff you're talking about is.

1. OpenGL is not software

OpenGL is a specification of a low-level graphics API, an abstract document describing and defining the system which is created and maintained by the OpenGL Architecture Review Board (ARB). The point when it becomes software is when someone implements the specification. Usually, and especially on Windows, implementation are packed with drivers for your respective GPU, e.g. AMD's Catalyst and NVIDIA's GeForce drivers.

2. GLUT

GLUT is a small, cross-platform GUI framework which is capable of creating OpenGL contexts and displaying the results of rasterization, among other things. Except for being able to be used in OpenGL development, GLUT is not part of the OpenGL specification.

*Note:*GLUT is very, very old and outdated. Please use FreeGLUT instead.

3. What are opengl32.lib and opengl32.dll?

Originally, Microsoft was a member of the ARB. When they parted and decided to specify Direct3D (as part of DirectX), they still provided and still do, an implementation of OpenGL 1.1 - this is what's residing in opengl32.dll. The lib is the so called import library which tells the linker how to resolve library symbols at runtime. See this for more.

Aside from the OpenGL 1.1 subset, opengl32.dll also implements the majority of the OpenGL bindings to the window system, called WGL. Check this for more.

Also, AFAIR, Microsoft's implementation is a pure software implementation - i.e. everything is done on the CPU.

4. How do you get more recent functionality?

As I already mentioned, you install GPU drivers which bring an OpenGL implementation. Currently, there are implementations of OpenGL 4.4 and 4.3 for NVIDIA and AMD GPUs respectively. The way Windows determines is by using registry entries set by the installed driver - also called an OpenGL installable client driver (OpenGL ICD). See this for more. At runtime, when you (or some toolkit like GLUT) create a context, Windows will load the implementation provided by the driver.

Afterwards, every entry-point determined by wglGetProcAddress is taken from the respective OpenGL implementation. For NVIDIA GPU, for instance, the name of the DLL containing the implementation is nvogl64.dll.

If you want access to new functionality, you either need to do exactly the above, i.e. retrieve pointers to functions from the loaded DLL, or use an OpenGL extension loader like the ones generated by glLoadGen or ready to use loaders like GLEW. (Personal note: Use glLoadGen!).

5. What is a minimum basic setup for OpenGL development on Windows?

This is the actual answer. For a bare OpenGL demo you don't even need anything like GLUT. You could implement stuff using only the Windows API, WGL and the GL implementation Windows offers. However, as soon as you want to go beyond OpenGL 1.1 and need hardware acceleration (which is probably the case 99,9% of the time), you'll want to use an extension loader or write loading code yourself to get access to recent OpenGL goodness.

If you're using MSVC(++), i.e. the compiler coming as part of Visual Studio, what you absolutely need to link against is

  • opengl32.lib - not matter if your application is a 64-bit or 32-bit application
  • if you're using GLU, you need glu32.lib
  • if you're using some GUI framework like GLUT, you need to link against their respective import libs. E.g., for GLUT it's glut32.lib. For Qt4 it would be QtOpenGL4.lib and so on.
  • you don't link against against some OpenGL ICD! As mentioned above, the entry-points of an ICD can only be determined dynamically at runtime via wglGetProcAddress.

If you have further questions or need clarification, leave a comment.

EDIT: Also, I urge you to check out the OpenGL wiki where we got a substantial amount of information on modern OpenGL.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top