【问题标题】:Failed to include GLUT C++未能包含 GLUT C++
【发布时间】:2020-12-11 16:40:39
【问题描述】:

我正在使用 MinGW 编译器,我的操作系统是 Windows,GLUT 在我的 Documents 文件夹中,文件 (Graphics.cpp) 也在我的 Documents 文件夹中,顺便说一下:

#include <GL/glut.h>
void drawSquare(double x1, double y1, double sidelength)
{
    double halfside = sidelength / 2;

    glColor3d(0,0,0);
    glBegin(GL_POLYGON);

    glVertex2d(x1 + halfside, y1 + halfside);
    glVertex2d(x1 + halfside, y1 - halfside);
    glVertex2d(x1 - halfside, y1 - halfside);
    glVertex2d(x1 - halfside, y1 + halfside);

    glEnd();
}

但是当我尝试编译代码时出现此错误:

Graphics.cpp:1:21: fatal error: GL/glut.h: No such file or directory
 #include <GL/glut.h>
                     ^
compilation terminated.

有人可以帮忙吗?需要任何其他信息吗? 谢谢。

【问题讨论】:

  • 为什么 GLUT 在你的桌面上?您需要实际安装它。您是否按照 GLUT 安装说明进行操作?
  • GLUT 在我的桌面上 这似乎不是一个好地方,但这是一个见仁见智的问题。我不会在桌面上放任何代码。
  • 正确安装 GLUT 后,确保包含 GL 文件夹的文件夹位于您告诉编译器查找包含文件的文件夹之一中。
  • @Asteroids With Wings 我只是把它移到那里,所以我记得它在哪里,它是暂时的所以没关系。
  • @drescherjm 已将 GLUT 移至 Documents 文件夹。

标签: c++ glut


【解决方案1】:

编译器似乎找不到标头。在 gcc 中使用 -I 标志来包含目录 GL/glut.h 的绝对路径

https://www.rapidtables.com/code/linux/gcc/gcc-i.html

【讨论】:

  • 哎呀,我的是g++,你知道g++怎么做吗?好吧,还是谢谢你的回答!如果我有足够的声誉,我会投票赞成。
  • gcc 和 g++ 使用相同的方式指定包含路径。
  • @drescherjm 好的,那我试试,谢谢!
  • @ralfhtp 嗯...到底怎么样? -.-
猜你喜欢
  • 2012-06-13
  • 2021-11-14
  • 1970-01-01
  • 2013-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多