【问题标题】:OpenGL C++ on Mac build fail 'GL/glut.h' file not foundMac 上的 OpenGL C++ 构建失败 'GL/glut.h' 文件未找到
【发布时间】:2015-03-13 04:09:16
【问题描述】:

尝试使用 xCode 在 OSX Yosemite 上运行示例 OpenGL C++ 程序。

运行程序时,我得到 'GL/glut.h' 文件未找到截图:

但是,我在项目中确实有 glut.h 标头:

在一个单独的论坛上,我读到它应该是“GLUT/glut.h”,所以我做了,但收到以下消息:

我需要做什么才能配置带有 C++ 的 OpenGL?

这是我要运行的代码。如果我可以运行它,那么我应该准备好一切:

#include <GLUT/glut.h>
#include <math.h>
//#include <stdlib.h>

const double TWO_PI = 6.2831853;

/*  Initial display-window size.  */
GLsizei winWidth = 400, winHeight = 400;
GLuint regHex;

class screenPt
{
private:
    GLint x, y;

public:
    /*  Default Constructor: initializes coordinate position to (0, 0).  */
    screenPt ( )  {
        x = y = 0;
    }

    void setCoords (GLint xCoord, GLint yCoord)  {
        x = xCoord;
        y = yCoord;
    }

    GLint getx ( ) const  {
        return x;
    }

    GLint gety ( ) const  {
        return y;
    }
};

static void init (void)
{
    screenPt hexVertex, circCtr;
    GLdouble theta;
    GLint k;

    /*  Set circle center coordinates.  */
    circCtr.setCoords (winWidth / 2, winHeight / 2);

    glClearColor (1.0, 1.0, 1.0, 0.0);   //  Display-window color = white.

    /*  Set up a display list for a red regular hexagon.
     *  Vertices for the hexagon are six equally spaced
     *  points around the circumference of a circle.
     */
    regHex = glGenLists (1);   //  Get an identifier for the display list.
    glNewList (regHex, GL_COMPILE);
    glColor3f (1.0, 0.0, 0.0);   //  Set fill color for hexagon to red.
    glBegin (GL_POLYGON);
    for (k = 0; k < 6; k++) {
        theta = TWO_PI * k / 6.0;
        hexVertex.setCoords (circCtr.getx ( ) + 150 * cos (theta),
                             circCtr.gety ( ) + 150 * sin (theta));
        glVertex2i (hexVertex.getx ( ), hexVertex.gety ( ));
    }
    glEnd ( );
    glEndList ( );
}

void regHexagon (void)
{
    glClear (GL_COLOR_BUFFER_BIT);

    glCallList (regHex);

    glFlush ( );
}

void winReshapeFcn (int newWidth, int newHeight)
{
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ( );
    gluOrtho2D (0.0, (GLdouble) newWidth, 0.0, (GLdouble) newHeight);

    glClear (GL_COLOR_BUFFER_BIT);
}

void main (int argc, char** argv)
{
    glutInit (&argc, argv);
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
    glutInitWindowPosition (100, 100);
    glutInitWindowSize (winWidth, winHeight);
    glutCreateWindow ("Reshape-Function & Display-List Example");

    init ( );
    glutDisplayFunc (regHexagon);
    glutReshapeFunc (winReshapeFcn);

    glutMainLoop ( );
}

【问题讨论】:

    标签: c++ xcode macos opengl glut


    【解决方案1】:

    当您将其更改为“GLUT/glut.h”时,它会正确找到标题。不幸的是,现在您收到了有关已弃用函数的所有警告消息。

    有关已弃用功能消息的修复,请参阅 xcode 5 deprecation warning about glut functionsGlut deprecation in Mac OSX 10.9, IDE: QT Creator

    您还会收到一条错误消息,指出您的主函数需要返回一个 int。这是阻止您的代码编译的原因,而不是警告。

    编辑 您应该将 main 函数更改为具有 int 的返回类型。

    int main(int argc, char *argv[])
    {
      /* code */
      return 0;
    }
    

    一些编译器会接受 void 作为 main 的返回类型,但这是一个非标准扩展。

    【讨论】:

    • 所以这是 OSX 问题?此外,如果我返回 0,它表示它不应该返回值。
    • 是的,在 OSX 10.9 中他们已经弃用了这些功能。这意味着他们会在某个时候删除它们并且并不真的希望您使用它们。不知道你的main函数有什么问题,能贴出代码吗?
    • 很有趣,因为这是我的教授给我们测试安装的测试代码。 (但在视觉工作室)。
    【解决方案2】:

    试试#include &lt;GLUT/glut.h&gt; 因为框架链接的名称是 GLUT。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-12
      • 2020-04-22
      • 1970-01-01
      • 1970-01-01
      • 2019-05-01
      • 2013-05-06
      • 2012-05-15
      相关资源
      最近更新 更多