0

I am having trouble making a simple OpenGL program. I did some research and found to make OpenGL programs I'll need

  • SFML - For creating window
  • GLEW - For extension handling

I have been using SFML for a while, it works fine. Following the official SFML page, and adding an additional linker option: -l opengl32 I managed to compile the typical OpenGL-with-SFML code shown Here.

So i moved on to make OpenGL applications, but i couldn't compile any of the tutorials on the net, due to undefinied references even after setting up GLEW. Now i have this piece of code taken from the least appreciated answer from here. I have followed the instructions from that post, but still getting errors:

C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c|| undefined reference to `wglGetProcAddress@4'

I am using

  • Windows 10
  • Codeblocks 16.1
  • Default MinGW packed with codeblocks
  • (SFML, GLEW)

**Edit:**

My full Build log:

-------------- Build: Debug in opengl_minus1 (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -LC:\prog\SFML\2.3.2\lib -LC:\prog\GLEW\1.13\lib -o bin\Debug\opengl_minus1.exe obj\Debug\main.o  -l opengl32  C:\prog\SFML\2.3.2\lib\libsfml-graphics.a C:\prog\SFML\2.3.2\lib\libsfml-window.a C:\prog\SFML\2.3.2\lib\libsfml-system.a C:\prog\GLEW\1.13\lib\libglew32.a
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x29c): undefined reference to `wglGetProcAddress@4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x2b8): undefined reference to `wglGetProcAddress@4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x2d4): undefined reference to `wglGetProcAddress@4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x2e8): undefined reference to `wglGetProcAddress@4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x2fc): undefined reference to `wglGetProcAddress@4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x310): more undefined references to `wglGetProcAddress@4' follow
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x1786c): undefined reference to `glGetString@4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x178bf): undefined reference to `wglGetCurrentDC@0'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x1792f): undefined reference to `wglGetProcAddress@4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x17943): undefined reference to `wglGetProcAddress@4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x1795e): undefined reference to `wglGetCurrentDC@0'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x179da): undefined reference to `wglGetProcAddress@4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x17b60): undefined reference to `wglGetProcAddress@4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x17b7c): undefined reference to `wglGetProcAddress@4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x17b9a): undefined reference to `wglGetProcAddress@4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x17f7c): undefined reference to `wglGetProcAddress@4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x17f98): more undefined references to `wglGetProcAddress@4' follow
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x19def): undefined reference to `glGetString@4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x19f40): undefined reference to `glGetString@4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x19f85): undefined reference to `wglGetProcAddress@4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x19fa1): undefined reference to `wglGetProcAddress@4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x19fbd): undefined reference to `wglGetProcAddress@4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x19fd6): undefined reference to `wglGetProcAddress@4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x1a08f): undefined reference to `wglGetProcAddress@4'
C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj):glew.c:(.text+0x1a0ab): more undefined references to `wglGetProcAddress@4' follow
C:/Program Files (x86)/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/4.9.2/../../../../mingw32/bin/ld.exe: C:\prog\GLEW\1.13\lib\libglew32.a(glew.obj): bad reloc address 0x13a98 in section `.rdata'
C:/Program Files (x86)/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/4.9.2/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
26 error(s), 0 warning(s) (0 minute(s), 0 second(s))
Community
  • 1
  • 1
Hamzsé
  • 29
  • 7

1 Answers1

0

The undefined reference to wglGetProcAddress occurs in member glew.obj of library libglew32 The function wglGetProcAddress is defined in libopengl32 but is not linked because the linkage order of the libraries is the wrong way round.

In the linkage sequence, files that need symbol definitions must occur before the ones the provide the definitions, because the linker will only link an object module from a library if it provides a definition of at least one symbol that is already referenced in the linkage, but not yet defined.

So link -lopengl32 after libglew32.a

Mike Kinghan
  • 55,740
  • 12
  • 153
  • 182