2011-08-07 38 views
0

使用Eclipse 3.6.2,當前版本的CDT,當前的Cygwin工具和C++(GCC)編譯器。鏈接-lglu32,-lglut32,-lopengl32。Windows上的Eclipse中的OpenGL,設置幫助w /鏈接錯誤?

我試圖讓這個環境中建立對OpenGL開發和正在運行到鏈接,我一直未能解決的錯誤。相關OpenGL和過剩庫和頭文件的最新版本已被複制到C:\ Cygwin的\ lib和C:\ Cygwin的的\ usr \包括\ w32api

例如,而這個編譯和鏈接..

#include <windows.h> 

#include <GLES2/gl2.h> 

#include <EGL/egl.h> 

#include <GL/glut.h> 

[...] 

void display() { 

    glClear(GL_COLOR_BUFFER_BIT); /* Clear the screen with the clear color */ 

glBegin(GL_TRIANGLES); 
    glVertex3f(-0.5,-0.5,0.0); 
    glVertex3f(0.5,0.0,0.0); 
    glVertex3f(0.0,0.5,0.0); 
glEnd(); 

glutSwapBuffers(); 

}

以下代碼在glVertextAttribPointer,glEnableVertexAttribArray和glDisableVertexAttribArray方法中拋出未定義的引用錯誤。

void display() { 

glClear(GL_COLOR_BUFFER_BIT); /* Clear the screen with the clear color */ 

    // map the border vertices 
glVertexAttribPointer(crosshairVertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &crossVertices[0]); 
glEnableVertexAttribArray(crosshairVertexHandle); 


glLineWidth(2.0f); 
glDrawArrays(GL_LINES, 0, 4); 
glDisableVertexAttribArray(crosshairVertexHandle); 

glutSwapBuffers(); /* Double buffering */ 

}

這裏的錯誤。對於項目

構建配置調試的ogl_tests **

make all 
Building file: ../src/ogl_tests.cpp 
Invoking: Cygwin C++ Compiler 
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/ogl_tests.d" -MT"src/ogl_tests.d" -o"src/ogl_tests.o" "../src/ogl_tests.cpp" 

Finished building: ../src/ogl_tests.cpp 

Building target: ogl_tests.exe 
Invoking: Cygwin C++ Linker 
g++ -o"ogl_tests.exe" ./src/ogl_tests.o -lglu32 -lglut32 -lopengl32 
./src/ogl_tests.o: In function `_Z7displayv': 
/cygdrive/c/Users/David/workspace/ogl_tests/Debug/../src/ogl_tests.cpp:61: undefined reference to `[email protected]' 
/cygdrive/c/Users/David/workspace/ogl_tests/Debug/../src/ogl_tests.cpp:62: undefined reference to `[email protected]' 
/cygdrive/c/Users/David/workspace/ogl_tests/Debug/../src/ogl_tests.cpp:67: undefined reference to `[email protected]' 
collect2: ld returned 1 exit status 
make: *** [ogl_tests.exe] Error 1 

任何想法? - 我使用的cygwin路徑是否正確?

+0

忘了提及這是一個Vista 64系統。 – olo

回答

1

@Nicol流星錘給你的困惑,我給你另一種PICE:您正在使用超越的OpenGL 1.1,但即使OpenGL的1.4的功能OpenGL函數。在Windows上,OpenGL功能必須通過擴展機制獲得。

最簡單的方法來做到這一點是使用擴展的包裝像GLEW或GLEE。創建上下文後,必須使用glewInit()對GLEW進行初始化。 GLEE可以在沒有初始化的情況下使用(在首次調用擴展函數時隱式發生)。

+0

啊哈!謝謝你和Nicol。問題解決了。GLEE做了詭計。我沒有意識到,更高版本的OpenGL的功能被視爲擴展。 – olo

1

OpenGL是的OpenGL ES。這是兩個完全不同的東西(儘管它們表面上看起來很相似)。如果您運行的是Vista 64,則可能是您沒有在運行OpenGL ES實現的系統上運行。

有一個OpenGL擴展,使您可以在桌面上創建的窗口的OpenGL ES的背景。但是它還沒有被廣泛實現,並且你沒有在你的代碼中使用它。哦,GLUT不能使用OpenGL ES。

EGL同樣不普及,特別是在Windows上。在Windows上編寫EGL實現方面存在一些噪音,但沒有任何結果。

所以你的兩個頭文件沒有任何意義。你應該包括OpenGL的東西,而不是OpenGL ES。

+0

我有一個安裝在這個系統上的JNI工作的Android構建環境,其中包括一個ES實現。我使用它們的原因是#include 導致相同函數出現'未聲明'錯誤。'../src/ogl_tests.cpp:在函數void display()中: ../src /ogl_tests.cpp:62:錯誤:'glVertexAttribPointer'未申報(首次使用此功能)... – olo