OpenGL SuperBible 第 5 版设置问题

发布于 2024-10-31 12:33:53 字数 8607 浏览 2 评论 0 原文

好的,所以我最近得到了 OpenGL SuperBible,并将 Code::Blocks 上的目录设置为 freeglutGLTools.h 但是这些 #include 语句将不起作用:

#include <GLtools.h>
#include <GLShaderManager.h>
#include <iostream>
#include <GL/glut.h>

要设置目录,我通过“设置”-> “编译器和调试器...”-> “搜索目录”选项卡并将其添加到“编译器”选项卡下(还有“链接器”和“资源编译器”选项卡):

C:\CodeBlocks\SB5\Src\GLTools\include

这些

C:\CodeBlocks\SB5\freeglut-2.6.0\include

是我得到的错误:

C:\CodeBlocks\SB5\freeglut-2.6.0\include\GL\freeglut_std.h|60|warning: "NOMINMAX" redefined|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\mingw32\bits\os_defines.h|46|warning: this is the location of the previous definition|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|225|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|226|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|227|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|228|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|229|error: 'GLAPI' does not name a type|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|230|error: 'GLAPI' does not name a type|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|231|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|232|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|233|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|234|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|235|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|236|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|237|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|238|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|239|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|240|error: expected constructor, destructor, or type conversion before 'const'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|241|error: expected constructor, destructor, or type conversion before 'const'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|242|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|243|error: expected constructor, destructor, or type conversion before 'const'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|244|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|245|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|246|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|247|error: 'GLAPI' does not name a type|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|248|error: 'GLAPI' does not name a type|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|249|error: 'GLAPI' does not name a type|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|250|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|251|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|252|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|253|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|254|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|255|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|256|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|257|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|258|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|259|error: 'GLAPI' does not name a type|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|260|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|261|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|262|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|263|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|264|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|265|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|266|error: 'GLAPI' does not name a type|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|267|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|268|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|269|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|270|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|271|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|272|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|273|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|274|error: expected constructor, destructor, or type conversion before 'void'|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build finished: 50 errors, 2 warnings ===|

似乎标头之间存在某种冲突文件,尽管当我什至没有包含它时,它在 glu.h 处出现了错误。

Ok, so I've recently got the OpenGL SuperBible, and set up the directories on Code::Blocks to freeglut and GLTools.h but these #include statements will not work:

#include <GLtools.h>
#include <GLShaderManager.h>
#include <iostream>
#include <GL/glut.h>

To set the directories I went through "Settings" -> "Compiler and Debugger..." -> "Search Directories" tab and added this under the "Compiler" tab (there's also "Linker" and "resource Compiler" tabs):

C:\CodeBlocks\SB5\Src\GLTools\include

and

C:\CodeBlocks\SB5\freeglut-2.6.0\include

These are the errors I get:

C:\CodeBlocks\SB5\freeglut-2.6.0\include\GL\freeglut_std.h|60|warning: "NOMINMAX" redefined|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\mingw32\bits\os_defines.h|46|warning: this is the location of the previous definition|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|225|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|226|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|227|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|228|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|229|error: 'GLAPI' does not name a type|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|230|error: 'GLAPI' does not name a type|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|231|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|232|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|233|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|234|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|235|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|236|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|237|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|238|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|239|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|240|error: expected constructor, destructor, or type conversion before 'const'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|241|error: expected constructor, destructor, or type conversion before 'const'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|242|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|243|error: expected constructor, destructor, or type conversion before 'const'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|244|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|245|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|246|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|247|error: 'GLAPI' does not name a type|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|248|error: 'GLAPI' does not name a type|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|249|error: 'GLAPI' does not name a type|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|250|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|251|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|252|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|253|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|254|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|255|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|256|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|257|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|258|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|259|error: 'GLAPI' does not name a type|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|260|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|261|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|262|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|263|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|264|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|265|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|266|error: 'GLAPI' does not name a type|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|267|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|268|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|269|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|270|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|271|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|272|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|273|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|274|error: expected constructor, destructor, or type conversion before 'void'|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build finished: 50 errors, 2 warnings ===|

It seems as though there's some kind of conflict going on between the header files, although it's coming up with errors at glu.h when I didn't even include that.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遇见了你 2024-11-07 12:33:53

我在尝试编译《超级圣经》(第五版)中的三角形示例时遇到了与您相同的问题。我还喜欢将 Code::Blocks 与 MinGW 一起使用。我一直在做一些研究,我想我已经解决了大多数问题。

首先要做的是正确设置我们的环境。我们首先配置库、freeglut 和 GLTools。

在开始之前,请确保您已安装最新版本的 MinGW 和 MSYS。检查是否已将 c:/MinGW/bin 添加到路径变量中。还可以获得一个好的文件提取器,例如 7z,它可以解压 .tar 和 .gz 文件。

我可能会说得太详细,但在我研究之前,这些事情对我来说并不明显。

要设置 freeglut-2.6.0,我们要做的第一件事是从源代码编译静态库:

  1. 转到 freeglut 的 网站并下载最新版本(当前为 2.6.0)

  2. 创建 ac:/libs 目录,并在那里解压 freeglut 软件包。您最终应该得到一个名为 c:/libs/freeglut-2.6.0 的目录。

  3. 运行 MSYS (c:/MinGW/msys/1.0/msys.bat)。您应该位于主目录中(在顶行的用户和主机后面用 ~ 表示)。

  4. 输入“cd /c/libs/freeglut-2.6.0/src”并按 [enter]。 ~ 将更改为 /c/libs/freeglut-2.6.0/src 以表示您当前的工作目录。

  5. 输入“gcc -O2 -c -DFREEGLUT_STATIC *.c -I../include”并按[Enter]。我们在这里所做的是调用 gcc 编译器,指示它使用 O2 优化,设置标志 FREEGLUT_STATIC,并将该目录中的每个源文件编译为 .o 目标文件,并在“../include”中查找标头。这意味着向下一级(到 /c/libs/freeglut-2.6.0)并在那里查找 /include 目录。

  6. 输入“ar rcs libfreeglut32_static.a *.o”并按 Enter 键。据我所知,ar 是编译静态库、存档文件(.a)的实用程序。我们告诉它从我们在上一步中刚刚编译的每个目标文件 (.o) 创建“libfreeglut32_static.a”。

  7. 在 /c/libs/freeglut-2.6.0 中创建 /lib 目录。然后剪切我们刚刚创建的库并将其粘贴到该目录中。 freeglut 库的最终位置应为“c:/libs/freeglut-2.6.0/lib/libfreeglut32_static.a”。

请访问此网站了解更多信息使用 MinGW 编译 freeglut 的参考。

在让 GLTools 工作之前,请确保 freeglut 工作。

  1. 打开 Code::Blocks,并关闭所有打开的项目。转到“设置->编译器和调试器”并打开“搜索目录”选项卡。在编译器中,添加目录“c:/libs/freeglut-2.6.0/include/”。在链接器中,添加“c:/libs/freeglut-2.6.0/lib/”。

  2. 创建一个空项目。添加 test.cpp 文件。添加单个函数 int main (){return 0;}

  3. 构建应该没有问题。

  4. 添加#define FREEGLUT_STATIC#include

  5. 尝试编译。它将失败。

  6. 右键单击该项目并转到“构建选项”。确保您正在编辑整个项目的选项,而不是调试或发布目标。移至“链接器”选项卡,然后添加到链接库“freeglut32_static”。

  7. 尝试编译。又会失败。编译器将抛出“未定义的引用”错误,列出一堆函数。复制第一个的名称,然后在谷歌中查找。转到 Microsoft 搜索结果(第一个或第二个结果)。它将描述该函数,更重要的是,告诉您该函数位于哪个库中。

  8. 该库将被称为“something.lib”。再次转到“构建选项”,并将“something”添加到链接库中。

  9. 再次尝试编译。它将再次失败。如果您费心检查,您会发现第一个“未定义的引用”已更改。重复 7 和 8,直到不再失败。为了让 freeglut 正常工作,您必须添加的其他库是“Winmm”、“Gdi32”和“Opengl32”。

  10. 再次编译。应创建 test.exe。耶!

好吧,现在我们已经有了自由过剩的工作,是时候再次打破它了。我们首先要重新创建 GLTools 库,因为 SB5 仅分发 .lib 版本。

  1. SB5下载应该有4个主要目录; freeglut、linux、Visualstudio 和 src。进入src。复制 GLTools 目录并将其粘贴到“c:/libs”中。

  2. 在 GLTools 中创建一个 lib 目录。现在其中应该有三个目录:/include、/src 和 /lib。

  3. 再次启动 MSYS。输入“cd /c/libs/GLTools/src”并按 [enter]。

  4. 就像我们对 freeglut 所做的那样,我们将获取所有工具的代码并将其链接到一个库中。输入“g++ -c *.cpp -I../include”并按 [enter],然后输入“ar rcs libGLTools.a *.o”。

  5. 将输出 libGLTools.a 剪切到“c:/libs/GLTools/lib”中。

  6. 我们对 glew 也做了同样的事情。键入“g++ -c glew.c -I../include”,然后按 [enter]。然后“ar rcs libglew.a glew.o”。

  7. 在 Code::Blocks 中,返回“设置 -> 编译器和调试器”并打开“搜索目录”选项卡。在编译器中,添加目录“c:/libs/GLTools/include/”。在 Linker 中,添加“c:/libs/GLTools/lib/”。

  8. 我答应过我们会打破之前所做的事情,不是吗?添加到我们的测试程序 #include 并尝试构建项目。您应该会收到大量“'GLAPI' 未命名类型”错误。发生这种情况是因为,在某些时候(我自己不确定)GLAPI 没有被定义。或者它的定义是错误的。

如果您从未使用过这样的库,那么这是值得研究的(我没有,所以这对我来说也是一次学习经历)。当我们包含“glut.h”时,如果您打开头文件,您会看到它只是包含“freeglut_std.h”。所以你打开该文件,它有一堆预处理器命令。

在文档中搜索GLAPI,我们发现这里没有定义它。但是,它确实包括 。因此,打开 gl.h 并在那里运行搜索。

宾果!我们可以看到一些与 GLAPI 定义相关的命令。这有点令人困惑,但我们将复制预处理器通常所做的事情。所以我们在那里有这些行:

/* GLAPI, part 1 (use WINGDIAPI, if defined) */
#if defined(__WIN32__) && defined(WINGDIAPI)
#  define GLAPI WINGDIAPI
#endif

/* GLAPI, part 2 */
#if !defined(GLAPI)
#  if defined(_MSC_VER)                        /* Microsoft Visual C++ */
#    define GLAPI __declspec(dllimport)
#  elif defined(__LCC__) && defined(__WIN32__) /* LCC-Win32 */
#    define GLAPI __stdcall
#  else                                        /* Others (e.g. MinGW, Cygwin, non-win32) */
#    define GLAPI extern
#  endif
#endif

我们可以搜索 freeglut_std.h 并发现 WINGDIAPI 未定义。所以我们跳过第一个块。从第二个块中,我们可以看到我们想要的行是#define GLAPI extern

那么,似乎正在发生的事情是,GLTools 中的一个标头给我们弄乱了这个定义。除了尝试找出问题出在哪里之外,没什么可做的。

GLTools 没有提及任何有关 GLAPI 的信息,但在 。 h>。 glew.h 定义了 GLAPI 几次,但由于代码中没有标识,因此很难判断代码是否被输入。但很明显,出于我们的目的,GLAPI 必须定义为 extern。因此,我们将在 test.cpp 中进行快速修改,并在要包含的命令之前将 GLAPI 定义为 extern。

#include <GLTools.h>

#define FREEGLUT_STATIC
#define GLAPI extern
#include <GL/glut.h>

它仍然会被破坏,但我们应该得到一个退出的新错误!所以我们编译并......

呵呵。它编译没有错误。那不应该发生。但是,我们没有调用 GLTools 中的任何函数,所以也许这并不那么奇怪。我们将碰碰运气,在triangle.ccp 中添加第二个包含内容,#include 。并编译,再次没有错误。

好的,我们几乎准备好构建示例了。现在我们开始用triangle.cpp的内容填充test.cpp,并在失败时进行测试。我首先在

GLBatch triangleBatch;
GLShaderManager shaderManager;

main 之外添加一些未定义的引用。这更像是这样。因此,我们打开“构建”选项(记住指定整个项目,而不是发布或调试目标)并将 GLTools 添加到链接库。我们这样做了,现在(如果您一直注意的话,您应该预料到)我们得到了一堆对 glew 函数的未定义引用。

威!太令人兴奋了。现在我们将 glew 库添加到构建选项中。如果你最后链接了glew,我们就会学到一些新东西。您必须记住,在链接库时,那些具有自己的依赖项的库必须先于它们所依赖的库进行链接。如果我们提前知道它们都依赖什么,那将会很有帮助,这样以后就可以画个地图什么的。

所以我们要链接freeglut,这取决于winmm、gdi32和opengl32。我们还需要GLTools,它依赖于glew,而glew,它依赖于opengl32。那么链接它们的顺序应该是... freeglut、GLTools、glew、winmm、gdi32 和 opengl32。让我们看看这是否有效......

哈!它编译没有错误。该死的,我很好(不是真的:()。

好的,既然我们设置了环境,我复制了 Triangle.cpp 文件的其余部分,保存,构建,并且没有错误。

我已经在中测试了这些步骤两台计算机,并且它们可以工作。我认为任何使用 Code::Blocks 和 MinGW 的人都可以在 OpenGL SuperBible,第五版中构建教程。

I ran into the same problem as you did when trying to compile the Triangle example in the SuperBible (5th Edition). I also like to use Code::Blocks with MinGW. I have been doing some research, and I think I've managed to solve most issues.

The first thing to do is to correctly set up our environment. We start by configuring the libraries, freeglut and GLTools.

Before getting started, make sure you have the latest version of MinGW installed, with MSYS. Check that you added c:/MinGW/bin to the path variable. Also get a good file extractor like 7z, that can unpack .tar and .gz files.

I'm going to be perhaps too detailed, but these things were not obvious to me until I researched them.

To set up freeglut-2.6.0, the first thing we are going to do is compile the static library from the source:

  1. Go to freeglut's site and download the latest version (currently 2.6.0)

  2. Create a c:/libs directory, and unpack the freeglut package there. You should end up with a directory called c:/libs/freeglut-2.6.0.

  3. Run MSYS (c:/MinGW/msys/1.0/msys.bat). You should be in your home directory (denoted by ~ after your user and host in the top line).

  4. Type "cd /c/libs/freeglut-2.6.0/src" and press [enter]. The ~ will change to /c/libs/freeglut-2.6.0/src to denote your current working directory.

  5. Type "gcc -O2 -c -DFREEGLUT_STATIC *.c -I../include" and press [enter]. What we are doing here is calling the gcc compiler, instructing it to use O2 optimization, set the flag FREEGLUT_STATIC, and compile every source file in this directory into .o object files, and to look for headers in "../include". That means to go down one level (to /c/libs/freeglut-2.6.0) and look for the /include directory there.

  6. Type "ar rcs libfreeglut32_static.a *.o" and press enter. To the best of my understanding, ar is the utility that compiles static libraries, archive files (.a). We're telling it to create "libfreeglut32_static.a" from every object file (.o) we just compiled in the previous step.

  7. Create a /lib directory in /c/libs/freeglut-2.6.0. Then cut the library we just created and paste it in this directory. The final location of the freeglut library should be "c:/libs/freeglut-2.6.0/lib/libfreeglut32_static.a".

Go to this site for further reference on compiling freeglut with MinGW.

Before getting GLTools working, make sure freeglut works.

  1. Open Code::Blocks, and close any open projects. Go to "Settings->Compiler and Debugger" and open the "Search Directory" tab. In Compiler, add the directory "c:/libs/freeglut-2.6.0/include/". In Linker, add "c:/libs/freeglut-2.6.0/lib/".

  2. Create an empty project. Add a test.cpp file. Add the single function int main (){return 0;}.

  3. It should build with no problem.

  4. Add #define FREEGLUT_STATIC and #include <GL/glut.h>.

  5. Try to compile. It will fail.

  6. Right click on the Project and go to "Build Options". Make sure you are editing the options for the whole project, not the Debug or Release targets. Move to the Linker tab, and add to Link libraries "freeglut32_static".

  7. Try to compile. It will fail again. The compiler will throw "undefined reference to" errors, listing a bunch of functions. Copy the name of the first one, and look it up in google. Go to the microsoft search result (first or second result). It will describe the function, and more importantly, tell you what library that function is in.

  8. The library will be called "something.lib". Go to Build Options again, and add "something" to the link libraries.

  9. Try compiling again. It will fail once more. If you bother to check, you'll see that the first "undefined reference" has changed however. Repeat 7 and 8 until it stops failing. The additional libraries you'll have to add to get freeglut working are "Winmm", "Gdi32" and "Opengl32".

  10. Compile once more. test.exe should be created. Yay!

Ok, now that we have freeglut working, it's time to break it again. We are first going to recreate the GLTools library, since the SB5 only distributes the .lib version.

  1. The SB5 download should have 4 main directories; freeglut, linux, visualstudio and src. Go into src. Copy the GLTools directory and paste it in "c:/libs".

  2. Create a lib directory within GLTools. There should now be three directories within it, /include, /src and /lib.

  3. Bring up MSYS again. Type "cd /c/libs/GLTools/src" and press [enter].

  4. Like we did with freeglut, we're going to grab all the tools' code and link it into a single library. Type "g++ -c *.cpp -I../include" and press [enter], followed by "ar rcs libGLTools.a *.o".

  5. Cut the output, libGLTools.a, into "c:/libs/GLTools/lib".

  6. We do the same for glew. Type "g++ -c glew.c -I../include" followed by [enter]. Then "ar rcs libglew.a glew.o".

  7. In Code::Blocks, go back to "Settings->Compiler and Debugger" and open the "Search Directory" tab. In Compiler, add the directory "c:/libs/GLTools/include/". In Linker, add "c:/libs/GLTools/lib/".

  8. I promised we'd break what we had done before, didn't I? Add to our test program #include <GLTools.h> and try to build the project. You should get a slew of "'GLAPI' does not name a type" errors. This is happening because, at some point (not sure where myself) GLAPI is not getting defined. Or it is getting defined wrong.

This is worth investigating, if you've never worked with libraries like this (I haven't, so it's a learning experience for me as well). When we include "glut.h", if you open the header file you'll see it is simply including "freeglut_std.h". So you open that file, and it has a bunch of preprocessor commands.

Run a search for GLAPI in the document, and we find out it doesn't define it here. It does, however, include <GL/gl.h> and <GL/glu.h>. So open gl.h and run a search there.

Bingo! We can see a few commands that play around with our GLAPI definition. This is a little confusing, but we're going to copy what the preprocessor normally does. So we have these lines in there:

/* GLAPI, part 1 (use WINGDIAPI, if defined) */
#if defined(__WIN32__) && defined(WINGDIAPI)
#  define GLAPI WINGDIAPI
#endif

/* GLAPI, part 2 */
#if !defined(GLAPI)
#  if defined(_MSC_VER)                        /* Microsoft Visual C++ */
#    define GLAPI __declspec(dllimport)
#  elif defined(__LCC__) && defined(__WIN32__) /* LCC-Win32 */
#    define GLAPI __stdcall
#  else                                        /* Others (e.g. MinGW, Cygwin, non-win32) */
#    define GLAPI extern
#  endif
#endif

We can search freeglut_std.h and find out WINGDIAPI is not defined. So we skip the first block. From the second block, we can see that the line we want is #define GLAPI extern.

What seems to be happening is, then, that one of the headers in GLTools is messing up this definition for us. There's little to do but try to figure out where the problem is.

GLTools doesn't say anything about GLAPI, but includes <windows.h> and <GL/glew.h> before <GL/gl.h>. glew.h defines GLAPI a couple of times, but because there's no identation in the code it's kind of confusing to tell if the code is being entered or not. What is clear, though, is that for our purposes GLAPI has to be defined as extern. So we're going to do a quick hack in our test.cpp and define GLAPI as extern right ahead of the command to include .

#include <GLTools.h>

#define FREEGLUT_STATIC
#define GLAPI extern
#include <GL/glut.h>

It's still going to be broken, but we should get an exiting NEW error! So we compile and....

Huh. It compiled with no errors. That shouldn't have happened. But then, we're not calling any of the functions in GLTools, so maybe it's not so strange. We'll press our luck and add the second include in triangle.ccp, #include <GLShaderManager.h>. And compile, and again no errors.

Ok, so we are almost ready to build the example. Now we start filling test.cpp with the contents of triangle.cpp, and test when it fails. I start by adding

GLBatch triangleBatch;
GLShaderManager shaderManager;

outside of main, and there we go, a couple of undefined references. That's more like it. So we open Build options (remember to specify the whole project, not the release or debug targets) and add GLTools to Link libraries. We do that, and now (as you should be expecting if you've been paying attention) we get a bunch of undefined references to glew functions.

Wee! So exciting. So now we add the glew library to the Build options. If you linked glew at the end, we learn something new. You have to remember that when linking libraries, those that have their own dependencies have to be linked ahead of the ones they depend on. It would be helpful if we knew what they all depend on ahead of time, so in the future draw a map or something.

So we want to link freeglut, that depends on winmm, gdi32 and opengl32. We also want GLTools, that depends on glew, and glew, that depends on opengl32. The order to link them in should be, then... freeglut, GLTools, glew, winmm, gdi32 and opengl32. Let's see if that works....

Ha! It compiled with no errors. Damn I'm good (not really :( ).

Ok, now that we set up the environment, I copied the rest of the Triangle.cpp file over, saved, build, and got no errors.

I've tested these steps in two computers, and they worked. I think the steps above should enable anyone with Code::Blocks and MinGW to build the tutorials in the OpenGL SuperBible, 5th Edition.

请持续率性 2024-11-07 12:33:53

在测试一些教程中的代码时,我已经为这个问题苦苦挣扎了几天。我想这是因为它们中的大多数都是用 Visual C/C++ 制作的,但我真的想使用 C::B 和 MinGW 来完成这项任务。

我想我终于找到了解决这个问题的简单方法:

1)如果您还无法为 MinGW 正确安装 freeglut-2.6.0,请尝试从这里获取它:

http://files.transmissionzero.co.uk/software/development/GLUT/freeglut-MinGW.zip

解压并使 .h 和 .a 文件可供您的项目使用。保存 .dll 供以后使用。

2) 在包含 glut.h 之前添加这两个定义

#define GLUT_DISABLE_ATEXIT_HACK
#define GLAPI extern
#include <GL/glut.h>

3) 编译项目

4) 在运行可执行文件之前,将 freeglut.dll 复制到其目录

5) Happy GL Hacking (终于!)

Have been struggling with this problem for a couple days while testing code from a few tutorials. I suppose it's because most of them are made with Visual C/C++ in mind but I really wanted to use C::B with MinGW for this task.

Think I finally found an easy solution to this problem:

1) If you haven't been able to properly install freeglut-2.6.0 for MinGW yet, try grabbing it from here:

http://files.transmissionzero.co.uk/software/development/GLUT/freeglut-MinGW.zip

Unpack and make .h and .a files available to your project. Save .dll for later.

2) Add these two defines before including glut.h

#define GLUT_DISABLE_ATEXIT_HACK
#define GLAPI extern
#include <GL/glut.h>

3) Compile your project

4) Before running the executable, copy freeglut.dll to its directory

5) Happy GL Hacking (at last!)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文