2012-05-10 74 views
7

以前問過很多:如何使用MinGW在Windows上編譯GLEW 1.7.0源代碼?目標是從C++項目動態鏈接庫。使用MinGW在Windows上構建GLEW 1.7.0

更多信息:我正在與QtCreator合作,使用qmake構建。我在Windows 7上。到目前爲止,我已經嘗試/看過以下鏈接。

use posted batch file also tried to replace gcc with g++

static with vc++ libs, build dll.a reuse vc++ .dll

Get MSYS run shipped makefile

Info on initial issues

simple stuff using GLEW msvc++ binaries, works on my desktop

Unfortuantely所有張貼的解決方案,結束了我下面的錯誤消息,當我使用的編譯結果我工程中的t:

undefined reference to `[email protected]' 
debug/Ex04.o: In function `Z6initGLv': 
undefined reference to `[email protected]' 
undefined reference to `[email protected]' 
debug/Ex04.o: In function `Z8updateGLv': 
undefined reference to `[email protected]' 
undefined reference to `[email protected]' 
collect2: ld returned 1 exit status 
mingw32-make.exe[1]: *** [debug/ecg4.exe] Error 1 
mingw32-make.exe: *** [debug] Error 2 

我在這個問題上鬥智鬥勇。我已經雙重和三重檢查了qmake中的LIBS路徑和windows路徑變量,以包括glew dll所在的目錄。另外qmake的INCLUDEPATH應該沒問題。在這裏,反正在.pro文件的路徑:

LIBS += -L$$quote(C:/mypath/freeglut/lib/) -lfreeglut 
LIBS += -L$$quote(C:/mypath/glew-1.7.0/lib/) -lglew32 -lglew32mx 
#LIBS+= C:/mypath/glew-1.7.0/lib/libglew32.dll.a 
#LIBS+= C:/Programming/glew-1.7.0/lib/libglew32mx.dll.a 

#includepath for project and the required libraries 
INCLUDEPATH += ./include 
INCLUDEPATH += "C:/mypath/glew-1.7.0/include" 
INCLUDEPATH += "C:/mypath/freeglut/include" 

那麼,有沒有人在那裏誰可以給萬無一失一系列關於如何獲得GLEW 1.7.0源使用MinGW編譯指令?

回答

12

好吧,我解決了它。

基本上我正確地編譯了GLEW,據我所見。我忘了將-lopengl32 -lglu32添加到我項目中的LIBS路徑。出於某種原因,我需要在我的Qt/MinGW/Windows系統上執行此操作。在我的桌面上:Qt/VC++/Windows我不必這樣做。有沒有人對此有過解釋?

對於任何人在同樣的問題絆腳石:從GLEW homepage

    1. 下載源文件(.zip)編譯源,有不同的方式(在最初的問題參見鏈接)
      - >見底部(舊批處理文件不在github上)
    2. 將.dll.a文件放在一個目錄中,該目錄將成爲qmake中的LIBS路徑的一部分
    3. 把。dll文件到一個目錄這是systemvariable路徑的一部分
    4. 不要忘記在你的qmake項目文件

    這裏使用OpenGL,穀氨酸,GLEW鏈接是我的項目文件中的一個片段:

    #Required Libraries, replace with your path 
    # $$quote(...) for quoting pathes with spaces 
    
    LIBS += -L$$quote(C:/Programming/freeglut/lib/) -lfreeglut 
    LIBS += -L$$quote(C:/Programming/glew-1.7.0/lib/) -lglew32 -lglew32mx 
    # the following line is not necessary when working with VS compiler, odd 
    LIBS += -lopengl32 -lglu32 
    
    #includepath for project and the required libraries 
    INCLUDEPATH += ./include 
    INCLUDEPATH += "C:/Programming/glew-1.7.0/include" 
    INCLUDEPATH += "C:/Programming/freeglut/include" 
    

    反正非常感謝,也許這可以幫助一些人不能忘記的依賴:)

    乾杯, 莫里茨


    編輯: 批處理文件不是任何更多,我不得不GLEW 1.9.0編譯。所以這裏有一些進一步的說明:

    1. 請確保ar.exe和gcc.exe在你的路徑上。對於「QtSDK標準安裝」,這些程序可以在C:\ QtSDK \ mingw \ bin;
    2. 將以下幾行放入glew-1.x.y文件夾中的批處理文件中。這是LightningIsMyName's Answer

      gcc -DGLEW_NO_GLU -O2 -Wall -W -Iinclude -DGLEW_BUILD -o src/glew.o -c src/glew.c 
      gcc -shared -Wl,-soname,libglew32.dll -Wl,--out-implib,lib/libglew32.dll.a -o lib/glew32.dll src/glew.o -L/mingw/lib -lglu32 -lopengl32 -lgdi32 -luser32 -lkernel32 
      ar cr lib/libglew32.a src/glew.o 
      
      gcc -DGLEW_NO_GLU -DGLEW_MX -O2 -Wall -W -Iinclude -DGLEW_BUILD -o src/glew.mx.o -c src/glew.c 
      gcc -shared -Wl,-soname,libglew32mx.dll -Wl,--out-implib,lib/libglew32mx.dll.a -o lib/glew32mx.dll src/glew.mx.o -L/mingw/lib -lglu32 -lopengl32 -lgdi32 -luser32 -lkernel32 
      ar cr lib/libglew32mx.a src/glew.mx.o 
      
    3. 運行批處理文件的精簡版。結果將在lib /文件夾中。生成的.dll和.dll.a文件放在一起(.dll.a是您想要告訴鏈接器的內容,.dll應該在運行時可供系統使用)。 .a文件用於靜態鏈接。

  • +1

    感謝您的提示,我詳細闡述了答案並接受了它。 –

    +0

    我編輯了答案以刪除損壞的鏈接並替換丟失的信息。希望現在不會太混亂。 –

    相關問題