c++ - OpenGL程序可编译但无法正确启动

标签 c++ opengl freeglut

我正在尝试OpenGL和C++,在编写程序时遵循了this video tutorial(我的代码与他的代码完全相同)。我还按照freeglut网站here上的说明设置了freeglut,编译并链接了我的程序。源代码编译没有问题,但是当我尝试运行exe时出现错误。我能想到的唯一原因是我没有使用IDE,所以在运行exe时可能会丢失一些编译步骤或缺少一些命令行参数,而IDE会自动完成这些操作。有人可以告诉我正确运行程序需要做什么吗?

这是我的代码:

#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();
}

当我编译时,我运行
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

然后,我尝试运行hello.exe,但仅收到错误消息“应用程序无法正确启动(0xc000007b)”。

顺便说一句,我看到了这个duplicate question,但我尝试将dll放在同一目录中(从一开始就在该目录中),但这没有任何改变。

最佳答案

在我的项目中使用32位freeglut dll(而不是64位dll)解决了该问题。

关于c++ - OpenGL程序可编译但无法正确启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60720120/

相关文章:

linux - 在 Linux 上安装 Freeglut

c++ - 使用 glutPostRedisplay() 绘制锯齿线

c++ - 初始化常量变量并在失败时断言 (c++)

c++ - 这看起来像什么伪代码?

c++ - 在c++中搜索合适的数据结构

c++ - 拦截传入的短信

c++ - 如何使用鼠标滚轮修复放大和缩小?

c++ - 纹理的理解

qt - 使用 opengl 绘制多个项目(现代)