anhadikal
anhadikal

Reputation: 45

OpenGL linker error on MinGW

I tryies to init OpenGL on windows without GLFW ... her some relevant code:

#include <windows.h>
//...
  if(!(g_hDC = GetDC(hWnd)))
    return false;

  if(!(iPixelFormat = ChoosePixelFormat(g_hDC, &pfdPixelFormat)))
    return false;

  if(!SetPixelFormat(g_hDC, iPixelFormat, &pfdPixelFormat))
    return false;

  if(!(g_hRC = wglCreateContext(g_hDC)))
    return false;

  if(!wglMakeCurrent(g_hDC, g_hRC))
    return false;
//...

when I compile with mingw32-g++ -Wall -O2 -Wl,--subsystem,windows -lopengl32 -mwindows Init.c I get following errors:

Temp\cclcIFFB.o:init.c:(.text+0x281): undefined reference to `_wglCreateContext@4'
Temp\cclcIFFB.o:init.c:(.text+0x2a0): undefined reference to `_wglMakeCurrent@8'
collect2.exe: error: ld returned 1 exit status

Why this linker error acours?

Upvotes: 1

Views: 1068

Answers (2)

genpfault
genpfault

Reputation: 52082

Try putting your Init.c before the -lopengl32:

mingw32-g++ -Wall -O2 Init.c -Wl,--subsystem,windows -lopengl32 -mwindows 

gcc can be picky about argument positioning.

Upvotes: 1

datenwolf
datenwolf

Reputation: 162164

You must add the OpenGL linker definition library opengl32.lib to the list of to be linked libraries.

Upvotes: 0

Related Questions