I'm trying to compile a sample OpenGL for Windows code that uses WGL, and the compilation fails.
All the compiler errors look like: undefined reference to `wglCreateContext@4' (with different wglFunctionNames)
The source code that throws this error:
...
#include <windows.h>
#include <GL\gl.h>
#include <GL\glu.h>
...
hRC = wglCreateContext(hDC); <- this causes an error
...
I compile from the commandline using
g++ -Wall -mwindows -static-libstdc++ -lopengl32 main.cpp -o out
Accordingly to ms documentation at: https://msdn.microsoft.com/en-us/library/windows/desktop/dd374379(v=vs.85).aspx
Requirements:
Header Wingdi.h
Library Opengl32.lib
DLL Opengl32.dll
(do I need to include Wingdi.h to use wglFunctions...?) I have opengl32.dll on my system at C:\Windows\System32\opengl32.dll I have libopengl32.a at C:\MinGW\lib\libopengl32.a main.cpp is located at D:\dev\cpp\main.cpp
This is as far as my research got me, I'm stuck. Tried lots of different compiler flags, but none worked.
I know there are things like freeglut that can let me get around this issue completely, but I'd like to know how to get this to work. So, what do I need to change, to stop getting undefined references to wgl[functionName]s in my code? (wglCreateContext was just one example. every wglFunctionName throws a reference error)