I am new to OpenGL programming . I am trying to compile the following C code using MinGW w64 GCC compiler in Windows 10 . But I am getting the following error . I think it is a linking error.
The source code:
#include <stdlib.h>
#include <stdio.h>
#include "GLEW/glew.h"
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include "GLUT/glut.h"
#endif
static int make_resources(void)
{
return 1;
}
static void update_fade_factor(void)
{
}
static void render(void)
{
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glutSwapBuffers();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize(400, 300);
glutCreateWindow("Hello World");
glutDisplayFunc(&render);
glutIdleFunc(&update_fade_factor);
glewInit();
if (!GLEW_VERSION_2_0)
{
fprintf(stderr, "OpenGL 2.0 not available\n");
return 1;
}
if (!make_resources())
{
fprintf(stderr, "Failed to load resources\n");
return 1;
}
glutMainLoop();
return 0;
}
The powershell command the compile the code:
gcc -o hi.exe .\main.c -L. .\glut32.lib .\glew32.lib
The liking error:
PS C:\Users\Blue\Documents\CODE_FILES\VS_CodeDev\opengl_projects\1> gcc -o hi.exe .\main.c -L. .\glut32.lib .\glew32.lib
C:\Users\Blue\AppData\Local\Temp\ccKasHc9.o:main.c:(.text+0x2e): undefined reference to `glClearColor@16'
C:\Users\Blue\AppData\Local\Temp\ccKasHc9.o:main.c:(.text+0x3d): undefined reference to `glClear@4'
C:\Users\Blue\AppData\Local\Temp\ccKasHc9.o:main.c:(.text+0x45): undefined reference to `glutSwapBuffers'
C:\Users\Blue\AppData\Local\Temp\ccKasHc9.o:main.c:(.text+0x68): undefined reference to `glutInit'
C:\Users\Blue\AppData\Local\Temp\ccKasHc9.o:main.c:(.text+0x74): undefined reference to `glutInitDisplayMode'
C:\Users\Blue\AppData\Local\Temp\ccKasHc9.o:main.c:(.text+0x88): undefined reference to `glutInitWindowSize'
C:\Users\Blue\AppData\Local\Temp\ccKasHc9.o:main.c:(.text+0x94): undefined reference to `glutCreateWindow'
C:\Users\Blue\AppData\Local\Temp\ccKasHc9.o:main.c:(.text+0xa0): undefined reference to `glutDisplayFunc'
C:\Users\Blue\AppData\Local\Temp\ccKasHc9.o:main.c:(.text+0xac): undefined reference to `glutIdleFunc'
C:\Users\Blue\AppData\Local\Temp\ccKasHc9.o:main.c:(.text+0xb1): undefined reference to `_imp__glewInit@0'
C:\Users\Blue\AppData\Local\Temp\ccKasHc9.o:main.c:(.text+0xb8): undefined reference to `_imp____GLEW_VERSION_2_0'
C:\Users\Blue\AppData\Local\Temp\ccKasHc9.o:main.c:(.text+0x12b): undefined reference to `glutMainLoop'
collect2.exe: error: ld returned 1 exit status
I am not using Visual Studio because I want to do things manually.