Gri*_*fin 4 c++ compiler-construction opengl
好了,我最近得到了OpenGL的OpenGL超级,并设置上的目录编号:: Blocks的以freeglut和GLTools.h,但这些#include声明将无法正常工作:
#include <GLtools.h>
#include <GLShaderManager.h>
#include <iostream>
#include <GL/glut.h>
Run Code Online (Sandbox Code Playgroud)
要设置目录,我通过"设置" - >"编译器和调试器..." - >"搜索目录"选项卡,并在"编译器"选项卡下添加它(还有"链接器"和"资源编译器"选项卡):
C:\CodeBlocks\SB5\Src\GLTools\include
Run Code Online (Sandbox Code Playgroud)
和
C:\CodeBlocks\SB5\freeglut-2.6.0\include
Run Code Online (Sandbox Code Playgroud)
这些是我得到的错误:
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 ===|
Run Code Online (Sandbox Code Playgroud)
好像在头文件之间发生了某种冲突,虽然它在glu.h我甚至没有包含它时会出现错误.
请帮忙!谢谢!=)
Kia*_*ian 14
我在尝试编译SuperBible(第5版)中的Triangle示例时遇到了同样的问题.我也喜欢使用Code :: Blocks with MinGW.我一直在做一些研究,我想我已经设法解决了大多数问题.
首先要做的是正确设置我们的环境.我们首先配置库,freeglut和GLTools.
在开始之前,请确保使用MSYS安装了最新版本的MinGW.检查是否已将c:/ MinGW/bin添加到路径变量中.还可以获得像7z这样的好文件提取器,它可以解压缩.tar和.gz文件.
我可能会过于详细,但在研究它们之前,这些事情对我来说并不明显.
要设置freeglut-2.6.0,我们要做的第一件事是从源代码编译静态库:
转到freeglut的网站并下载最新版本(目前为2.6.0)
创建ac:/ libs目录,并在那里解压缩freeglut包.您应该得到一个名为c:/libs/freeglut-2.6.0的目录.
运行MSYS(c:/MinGW/msys/1.0/msys.bat).您应该在您的主目录中(在您的用户和主机位于顶行之后用〜表示).
输入"cd /c/libs/freeglut-2.6.0/src"并按[enter].〜将更改为/c/libs/freeglut-2.6.0/src以表示您当前的工作目录.
输入"gcc -O2 -c -DFREEGLUT_STATIC*.c -I ../ include"并按[enter].我们在这里做的是调用gcc编译器,指示它使用O2优化,设置标志FREEGLUT_STATIC,并将此目录中的每个源文件编译为.o目标文件,并在"../include"中查找标头.这意味着向下一级(到/c/libs/freeglut-2.6.0)并在那里查找/ include目录.
输入"ar rcs libfreeglut32_static.a*.o"并按Enter键.据我所知,ar是编译静态库,归档文件(.a)的实用程序.我们告诉它从我们刚刚在上一步中编译的每个目标文件(.o)创建"libfreeglut32_static.a".
在/c/libs/freeglut-2.6.0中创建/ lib目录.然后剪切我们刚刚创建的库并将其粘贴到此目录中.freeglut库的最终位置应为"c:/libs/freeglut-2.6.0/lib/libfreeglut32_static.a".
有关使用MinGW编译freeglut的更多参考,请访问此站点.
在让GLTools工作之前,请确保freeglut有效.
打开Code :: Blocks,关闭所有打开的项目.转到"设置 - >编译器和调试器",然后打开"搜索目录"选项卡.在编译器中,添加目录"c:/libs/freeglut-2.6.0/include/".在链接器中,添加"c:/libs/freeglut-2.6.0/lib/".
创建一个空项目.添加test.cpp文件.添加单个功能int main (){return 0;}.
它应该没有问题.
添加#define FREEGLUT_STATIC和#include <GL/glut.h>.
尝试编译.它会失败.
右键单击项目并转到"构建选项".确保您正在编辑整个项目的选项,而不是编辑调试或发布目标.移至链接器选项卡,然后添加到链接库"freeglut32_static".
尝试编译.它会再次失败.编译器将抛出"未定义的引用"错误,列出一堆函数.复制第一个名称,然后在谷歌中查找.转到Microsoft搜索结果(第一个或第二个结果).它将描述该函数,更重要的是,它将告诉您该函数所在的库.
该库将被称为"something.lib".再次转到Build Options,并在链接库中添加"something".
再次尝试编译.它会再次失败.如果你懒得检查,你会发现第一个"未定义的引用"已经改变了.重复7和8直到它停止失败.为了获得freeglut工作,你必须添加的附加库是"Winmm","Gdi32"和"Opengl32".
再次编译.应该创建test.exe.好极了!
好了,现在我们已经有了freeglut工作,现在是时候再次打破它了.我们首先要重新创建GLTools库,因为SB5只分发.lib版本.
SB5下载应该有4个主目录; freeglut,linux,visualstudio和src.进入src.复制GLTools目录并将其粘贴到"c:/ libs"中.
在GLTools中创建一个lib目录.现在应该有三个目录,/ include,/ src和/ lib.
再次启动MSYS.输入"cd/c/libs/GLTools/src"并按[enter].
就像我们使用freeglut一样,我们将抓住所有工具的代码并将其链接到一个库中.输入"g ++ -c*.cpp -I ../include"并按[enter],然后按"ar rcs libGLTools.a*.o".
将输出libGLTools.a剪切为"c:/ libs/GLTools/lib".
我们也为glew做同样的事情.输入"g ++ -c glew.c -I ../include",然后输入[enter].然后"ar rcs libglew.a glew.o".
在Code :: Blocks中,返回"Settings-> Compiler and Debugger"并打开"Search Directory"选项卡.在编译器中,添加目录"c:/ libs/GLTools/include /".在Linker中,添加"c:/ libs/GLTools/lib /".
我答应过我们打破以前做过的事,不是吗?添加到我们的测试程序#include <GLTools.h>并尝试构建项目.你应该得到一大堆"'GLAPI'并没有命名类型"的错误.这种情况正在发生,因为在某些时候(不确定我自己)GLAPI没有被定义.或者它被定义错了.
这是值得研究的,如果你从未与这样的图书馆合作过(我没有,所以这对我来说也是一次学习经历).当我们包含"glut.h"时,如果你打开头文件,你会发现它只包含"freeglut_std.h".所以你打开那个文件,它有一堆预处理器命令.
在文档中运行搜索GLAPI,我们发现它没有在此定义它.但它确实包括<GL/gl.h>和<GL/glu.h>.所以打开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
Run Code Online (Sandbox Code Playgroud)
我们可以搜索freeglut_std.h并找出WINGDIAPI没有定义.所以我们跳过第一个块.从第二个区块,我们可以看到我们想要的线路#define GLAPI extern.
那么,似乎正在发生的事情是,GLTools中的一个标题正在为我们弄乱这个定义.除了试图找出问题所在之外,没有什么可做的.
GLTools没有说GLAPI,但包括<windows.h>和<GL/glew.h>之前<GL/gl.h>.glew.h多次定义GLAPI,但由于代码中没有标识,因此判断代码是否输入有点令人困惑.但是,很明显,为了我们的目的,GLAPI必须被定义为extern.因此,我们将在test.cpp中快速入侵,并在命令包含之前将GLAPI定义为extern.
#include <GLTools.h>
#define FREEGLUT_STATIC
#define GLAPI extern
#include <GL/glut.h>
Run Code Online (Sandbox Code Playgroud)
它仍然会被打破,但我们应该得到一个退出的新错误!所以我们编译和....
呵呵.它编译没有错误.那不应该发生.但是,我们并没有调用GLTools中的任何函数,所以也许它并不那么奇怪.我们将运气好,并在triangle.ccp中添加第二个包含#include <GLShaderManager.h>.并编译,再没有错误.
好的,我们几乎准备好构建示例.现在我们开始使用triangle.cpp的内容填充test.cpp,并在失败时进行测试.我首先补充说
GLBatch triangleBatch;
GLShaderManager shaderManager;
Run Code Online (Sandbox Code Playgroud)
在main之外,我们去了几个未定义的引用.这还差不多.所以我们打开Build选项(记得指定整个项目,而不是发布或调试目标)并将GLTools添加到Link库.我们这样做,现在(正如你应该期待的那样,如果你一直在关注)我们得到一堆未定义的glew函数引用.
凌晨!如此令人兴奋.所以现在我们将glew库添加到Build选项中.如果你最后联系了glew,我们会学到一些新东西.您必须记住,在链接库时,那些具有自己的依赖项的库必须在它们依赖的库之前链接.如果我们提前知道他们所依赖的东西会很有帮助,所以将来会画出地图或其他东西.
所以我们要链接freeglut,这取决于winmm,gdi32和opengl32.我们也想要GLTools,这取决于glew和glew,这取决于opengl32.链接它们的顺序应该是,freeglut,GLTools,glew,winmm,gdi32和opengl32.让我们看看它是否有效......
哈!它编译没有错误.该死的我很好(不是真的:().
好了,现在我们设置了环境,我复制了Triangle.cpp文件的其余部分,保存,构建,并且没有错误.
我已经在两台计算机上测试了这些步骤,但它们都有效.我认为上面的步骤应该允许任何拥有Code :: Blocks和MinGW的人在OpenGL SuperBible,5th Edition中构建教程.
| 归档时间: |
|
| 查看次数: |
6743 次 |
| 最近记录: |