[英]OpenGL SuperBible 5th edition set-up problems
好的,所以我最近得到了OpenGL SuperBible,並將Code :: Blocks上的目錄設置為freeglut
和GLTools.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
出現錯誤。
請幫忙! 謝謝! =)
我在嘗試編譯SuperBible(第5版)中的Triangle示例時遇到了同樣的問題。 我也喜歡使用Code :: Blocks和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
我們可以搜索freeglut_std.h並找出WINGDIAPI沒有定義。 所以我們跳過第一個塊。 從第二個塊開始,我們可以看到我們想要的行是#define GLAPI extern
。
那么,似乎正在發生的事情是,GLTools中的一個標題正在為我們弄亂這個定義。 除了試圖找出問題所在之外,沒有什么可做的。
GLTools沒有說GLAPI,但在<GL/gl.h>
之前包含<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>
它仍然會被打破,但我們應該得到一個退出的新錯誤! 所以我們編譯和....
呵呵。 它編譯沒有錯誤。 那不應該發生。 但是,我們並沒有調用GLTools中的任何函數,所以也許它並不那么奇怪。 我們將運氣好,並在triangle.ccp, #include <GLShaderManager.h>
添加第二個包含。 並編譯,再沒有錯誤。
好的,我們幾乎准備好構建示例。 現在我們開始使用triangle.cpp的內容填充test.cpp,並在失敗時進行測試。 我首先補充說
GLBatch triangleBatch;
GLShaderManager shaderManager;
在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中構建教程。
在測試幾個教程中的代碼時,幾天來一直在努力解決這個問題。 我想這是因為大多數都是用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)快樂GL黑客(最后!)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.