2012-05-10 76 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

    我编辑了答案以删除损坏的链接并替换丢失的信息。希望现在不会太混乱。 –

    相关问题