c++ - 无法编译任何 opengl/freeglut/glut 源代码

标签 c++ opengl

我有从 opengl 示例代码中获取的代码:

#include <GL/glut.h>

// Display callback ------------------------------------------------------------

void display()
{
    // clear the draw buffer .
    glClear(GL_COLOR_BUFFER_BIT);   // Erase everything

    // set the color to use in draw
    glColor3f(0.5, 0.5, 0.0);       
    // create a polygon ( define the vertexs) 
    glBegin(GL_POLYGON); {           
        glVertex2f(-0.5, -0.5);
        glVertex2f(-0.5,  0.5);
        glVertex2f( 0.5,  0.5);
        glVertex2f( 0.5, -0.5);
    } glEnd();

    // flush the drawing to screen . 
    glFlush(); 
}

// Keyboard callback function ( called on keyboard event handling )
void keyboard(unsigned char key, int x, int y)
{
    if (key == 'q' || key == 'Q')
        exit(EXIT_SUCCESS);
}

// Main execution  function 
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);      // Initialize GLUT
    glutCreateWindow("OpenGL example");  // Create a window
    glutDisplayFunc(display);   // Register display callback
    glutKeyboardFunc(keyboard); // Register keyboard callback
    glutMainLoop();             // Enter main event loop

    return (EXIT_SUCCESS);
} 

应该可以吧? 但是当我运行它时:

Error   1   error LNK2019: unresolved external symbol __imp__glutMainLoop@0 referenced in function _main    C:\Users\Naor\documents\visual studio 2012\Projects\test\test\Source.obj    test
Error   2   error LNK2019: unresolved external symbol __imp__glutKeyboardFunc@4 referenced in function _main    C:\Users\Naor\documents\visual studio 2012\Projects\test\test\Source.obj    test
Error   3   error LNK2019: unresolved external symbol __imp__glutDisplayFunc@4 referenced in function _main C:\Users\Naor\documents\visual studio 2012\Projects\test\test\Source.obj    test
Error   4   error LNK2019: unresolved external symbol __imp____glutInitWithExit@12 referenced in function _glutInit_ATEXIT_HACK@8   C:\Users\Naor\documents\visual studio 2012\Projects\test\test\Source.obj    test
Error   5   error LNK2019: unresolved external symbol __imp____glutCreateWindowWithExit@8 referenced in function _glutCreateWindow_ATEXIT_HACK@4    C:\Users\Naor\documents\visual studio 2012\Projects\test\test\Source.obj    test
Error   6   error LNK1120: 5 unresolved externals   C:\Users\Naor\documents\visual studio 2012\Projects\test\Debug\test.exe 1   1   test

我正确安装了 opengl、freeglut(我的意思是,它运行并且 vc++ 发现没问题), 但我无法运行我找到的任何源代码..(同样的错误)

最佳答案

找到了答案,任何遇到此类问题的人请检查这些:

  1. 您已链接您的库并正确包含。 (推荐 32 位,修复了我的错误)。
  2. 完成此操作后,您可能会收到无法打开或找不到某些 dll 文件的错误。
  3. 检查它是什么 dll(在错误消息中),将其复制到您的 exe 所在的位置(对于 Debug模式到 Debug 文件夹,然后发布到 Release 文件夹)。

希望已经解决了你的错误 :)

关于c++ - 无法编译任何 opengl/freeglut/glut 源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19401441/

相关文章:

C++ 开关语句

visual-studio - 有什么方法可以在NVIDIA图形卡上的Visual Studio中运行程序调试?

c++ - opengl 平移与 glulookat

c++ - 不支持 GLSL 330 内核

c++ - 从抽象(纯虚拟)类私有(private)继承是否有意义?

c++ - CGAL 三角剖分边迭代器包括原点

c++ - 使用 OpenCV 随机森林,有什么方法可以获得分类的 "confidence"级别?

c++ - CCArray 与 std::vector

java - OpenGL Z 顺序困惑

c++ - 为什么我的纹理在我的 OpenGL 应用程序中渲染不正确?