2011-09-04 71 views
0

我有一個Linux的mingw32交叉編譯器,它在linux上編譯windows二進制文件。一切工作非常細,直到我需要安裝過剩......我在linux安裝了罰款,但每當我試圖在Windows上編譯同一個程序,我可以熬它歸結爲:如何在Linux上使用Windows交叉編譯器的glut?

/tmp/ccQhHDhy.o: 。main.cpp中:(文本+ 0xf):未定義參照__imp__glClear' /tmp/ccQhHDhy.o:main.cpp:(.text+0x1e): undefined reference to _ imp的 _glBegin' /tmp/ccQhHDhy.o:main.cpp:(.text+0x3d):未定義參照__imp__glVertex3f' /tmp/ccQhHDhy.o:main.cpp:(.text+0x5c): undefined reference to_ imp的 _glVertex3f」 /tmp/ccQhHDhy.o:main.cpp:(.text+0x7b):undefined reference to __imp__glVertex3f' /tmp/ccQhHDhy.o:main.cpp:(.text+0x85): undefined reference to _ imp _glEnd'

用的dll鏈接直接

獲得這些鏈接器錯誤後,我嘗試連接opengl32 GDI32 WINMM過剩LIB文件和glu32

,但仍然是相同的這

繼承人的源代碼:

#include <stdlib.h> 
#include <GL/glut.h> 
using namespace std; 
void render(void); 
int main(int argc, char **argv){ 
    glutInit(&argc, argv); 
    glutInitWindowPosition(-1,-1); 
    glutInitWindowSize(500,500); 
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); 
    glutCreateWindow("My First Glut Application"); 
    glutDisplayFunc(render); 
    glutMainLoop(); 
    return 0; 
} 

void render(void) 
{ 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

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


} 
+0

在你的情況下,它沒有那麼多的源代碼,我們需要查看,但編譯器/鏈接器調用。 – datenwolf

回答

2

你的程序,而不在Windows錯誤編譯。鏈接錯誤的原因可能是您沒有使用正確的makefile。但是,您的代碼中存在一些錯誤。您可以進行以下更改:

  • add glutSwapBuffers()render函數結束時。

然後使用的makefile MinGW的:

g++ -o prog -c prog.cpp -lopengl32 -lfreeglut -lglu32

+1

如上所述,您*必須*鏈接到庫,而不是DLL。 Dll是一個通常包含少量元數據的二進制文件,頭文件和庫提供使用dll所需的綁定(與共享對象相同的概念)。 – ssube

+0

'render'和'&render'之間沒有語義上的區別,它們都產生相同的結果。編寫'glutDisplayFunc(render)'不是錯誤。 – datenwolf

0

我終於嘗試freeglut和失敗交叉編譯之後。我得到了預編譯的Windows可執行文件,並改變
#include <GL/glut.h>

#include <GL/freeglut.h>

後,用freeglut32連接它的工作 和感謝肖恩指出這些錯誤

+0

如果您使用freeglut,則無需進行此更改。 freeglut packpage包含一個由「glut.h」命名的頭文件,這個頭文件將調用freeglut_std.h。該設置確保代碼跨平臺,也就是說,不需要更改代碼,只需更改makefile或編譯和鏈接命令 – Sean

相關問題