【问题标题】:GLUT and freeglut includes don't work together (MinGW)GLUT 和 freeglut 包括不能一起工作 (MinGW)
【发布时间】:2015-12-27 19:19:27
【问题描述】:

我正在使用带有 MinGW 编译器的 Code::Blocks。这些是我的包括:

#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

如果我尝试使用函数

glutMainLoopEvent();

它会抛出一个错误:

'glutMainLoopEvent' was not declared in this scope.

功能

glutMainLoop();

虽然效果很好。

如果我尝试同时包含 glut 和 freeglut(我已正确安装它,我确保按照步骤仔细观看了几次视频),如下所示:

#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#include <GL/freeglut.h>
#endif

我收到 24 个错误,例如:

undefined reference to `_imp____glutInitWithExit@12'
undefined reference to `_imp____glutCreateWindowWithExit@8'
undefined reference to `glClearColor@16'

但这些不包括我之前遇到的错误!据我所知,我可以包括 glut 或 freeglut,但不能同时包括两者。我该如何解决这个问题?谢谢!

编辑:

链接器选项:

-lfreeglut
-lopengl32
-lglu32

完全消除了问题,现在可以正常工作了。

【问题讨论】:

标签: c++ opengl include glut freeglut


【解决方案1】:

后面关于未定义引用的错误是链接器错误,而不是编译器错误。您必须将您的程序(除了包括头文件)链接到 glut 和/或 freeglut 库。这是通过向链接器添加以下选项来完成的:

-lfreeglu

【讨论】:

  • 请详细说明,我不知道从哪里开始。
  • @DDomjosa,链接器选项-l 后跟库名称告诉链接器在所述库中查找未解析的符号。在尝试使用 C++ 编写代码之前,您可以阅读链接器如何工作的基础知识。
  • @ThomasMcLeod 我学习 C++ 已经超过 3 个月了,而且我从来不需要弄乱链接器。诚然,我正在使用简单的命令行程序。
猜你喜欢
  • 1970-01-01
  • 2014-01-22
  • 2020-09-27
  • 1970-01-01
  • 1970-01-01
  • 2011-08-11
  • 2014-06-03
  • 1970-01-01
  • 2017-06-01
相关资源
最近更新 更多