OpenGL program compiles but doesn't start correctly

1

I'm trying out OpenGL and C++, and I followed this video tutorial on writing my program (my code is exactly the same as his). I also followed the instructions on the freeglut website here to set up freeglut, compile, and link my program. The source code compiles with no problem, but when I try running the exe I get an error. The only reason I could think of is that I'm not using an IDE, so I'm probably missing some compilation steps or missing some command line arguments when running the exe, which the IDE would have done automatically. Can someone tell me what I need to do to run my program correctly?

Here's my code:

#include <GL/glut.h>

void init() {
    glClearColor(1.0, 1.0, 0.0, 1.0);
}

void display() {
    glClear(GL_COLOR_BUFFER_BIT);
    glLoadIdentity();


    glFlush();
}

int main(int argc, char **argv) {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB);

    glutInitWindowPosition(200, 100);
    glutInitWindowSize(500, 500);

    glutCreateWindow("Window 1");

    glutDisplayFunc(display);
    init();

    glutMainLoop();
}

When I compile I run

gcc -c -o hello.o hello.cpp -I"C:\MinGW\include"
gcc -o hello.exe hello.o -L"C:\MinGW\lib" -lfreeglut -lopengl32 -Wl,--subsystem,windows

Then I try to run hello.exe but I only get an error message "The application was unable to start correctly (0xc000007b)".

BTW I saw this duplicate question but I've tried putting the dll in the same directory (it was there from the start) but that didn't change anything.

c++
opengl
freeglut
asked on Stack Overflow Mar 17, 2020 by Jason

1 Answer

0

Using the 32 bit freeglut dll (instead of the 64 bit dll) in my project fixed the problem.

answered on Stack Overflow Mar 18, 2020 by Jason

User contributions licensed under CC BY-SA 3.0