简体   繁体   English

使用 mingw 在 windows 上构建 glew

[英]Building glew on windows with mingw

Can anyone give me the correct command to build glew on windows with mingw?谁能给我正确的命令来使用 mingw 在 windows 上构建 glew?

I have tried:我试过了:

gcc -static glew.c glewinfo.c visualinfo.c -I/path/to/glew/include gcc -static glew.c glewinfo.c visualinfo.c -I/path/to/glew/include

but I am getting thousands of linker errors (missing reference).但我收到了数千个 linker 错误(缺少参考)。

I can't build with Make because unfortunately the makefile has lots of unix only commands and i don't have cygwin or anything at work.我不能用 Make 构建,因为不幸的是 makefile 有很多 unix 只有命令,我没有 cygwin 或任何工作。

(alternatively if anyone can point me to a windows 32b build i would be very grateful) (或者,如果有人能指出我的 windows 32b 版本,我将不胜感激)

To build it with MinGW, you should do (copied from the make log, with slight modifications and additional explanations):要使用 MinGW 构建它,您应该这样做(从 make 日志中复制,稍作修改和附加解释):

mkdir lib/
mkdir bin/
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

# Create library file: lib/libglew32.dll.a
ar cr lib/libglew32.a src/glew.o

# Create pkg-config file (optional if you just want a lib)
sed \
                -e "s|@prefix@|/usr|g" \
                -e "s|@libdir@|/usr/lib|g" \
                -e "s|@exec_prefix@|/usr/bin|g" \
                -e "s|@includedir@|/usr/include/GL|g" \
                -e "s|@version@|1.6.0|g" \
                -e "s|@cflags@||g" \
                -e "s|@libname@|GLEW|g" \
                < glew.pc.in > glew.pc

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

# Create library file: lib/libglew32mx.dll.a
ar cr lib/libglew32mx.a src/glew.mx.o

# Create pkg-config file (optional if you just want a lib)
sed \
                -e "s|@prefix@|/usr|g" \
                -e "s|@libdir@|/usr/lib|g" \
                -e "s|@exec_prefix@|/usr/bin|g" \
                -e "s|@includedir@|/usr/include/GL|g" \
                -e "s|@version@|1.6.0|g" \
                -e "s|@cflags@|-DGLEW_MX|g" \
                -e "s|@libname@|GLEWmx|g" \
                < glew.pc.in > glewmx.pc

# Make the glew visualinfo program. Skip this if you want just the lib
gcc -c -O2 -Wall -W -Iinclude  -o src/glewinfo.o src/glewinfo.c
gcc -O2 -Wall -W -Iinclude  -o bin/glewinfo.exe src/glewinfo.o -Llib  -lglew32 -L/mingw/lib -lglu32 -lopengl32 -lgdi32 -luser32 -lkernel32
gcc -c -O2 -Wall -W -Iinclude  -o src/visualinfo.o src/visualinfo.c
gcc -O2 -Wall -W -Iinclude  -o bin/visualinfo.exe src/visualinfo.o -Llib  -lglew32 -L/mingw/lib -lglu32 -lopengl32 -lgdi32 -luser32 -lkernel32

You should then have a lib folder and a bin folder with the desired executables and libraries然后你应该有一个 lib 文件夹和一个 bin 文件夹,其中包含所需的可执行文件和库

I got it working (with MinGW), i didn't compile the glew32mx but glew32 instead.我让它工作(使用 MinGW),我没有编译 glew32mx,而是编译 glew32。 Just download the source.zip from GLEW website.只需从 GLEW 网站下载 source.zip。 And remember create "lib" directory in the the glew-1.xx directory, otherwise it will complain about "can't find /lib/glew32.dll" when trying to compile the second line of code below:并记住在 glew-1.xx 目录中创建“lib”目录,否则在尝试编译下面第二行代码时会抱怨“找不到/lib/glew32.dll”:

    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

    # Create glew32.dll
    ar cr lib/libglew32.a src/glew.o

The precompiled binaries in GLEW website doesn't work with mingw, because they're compiled with visual studio, i think. GLEW 网站上的预编译二进制文件不适用于 mingw,因为我认为它们是用 visual studio 编译的。

Glew build system try to detect automatically your environment using config/configure.guess . Glew 构建系统尝试使用config/configure.guess自动检测您的环境。 You may overload this behaviour by specify $SYSTEM to make.您可以通过指定$SYSTEM来重载此行为。 See config/Makefile.* for all supported build configuration.请参阅config/Makefile.*了解所有支持的构建配置。 Glew already include configuration to use MinGW. Glew 已经包含使用 MinGW 的配置。

So, you may just have to launch:因此,您可能只需要启动:

make SYSTEM=linux-mingw64

On my Fedora, I had to tune some variables of config/Makefile.linux-mingw64 :在我的 Fedora 上,我不得不调整config/Makefile.linux-mingw64的一些变量:

  • $CC and $LD was not correct $CC$LD不正确
  • I had to specify directory where system libraries was located我必须指定系统库所在的目录
  • I had to specify where glew should be installed我必须指定应该安装 glew 的位置

Finally, I launched:最后,我推出了:

make SYSTEM=linux-mingw64                                       \
  CC=x86_64-w64-mingw32-gcc LD=x86_64-w64-mingw32-ld            \
  LDFLAGS.EXTRA=-L/usr/x86_64-w64-mingw32/sys-root/mingw/lib    \
  GLEW_DEST=/usr/x86_64-w64-mingw32/sys-root/mingw install

Found another solution that works with Code::Blocks.找到了另一个适用于 Code::Blocks 的解决方案。 Steps:脚步:

1) Obviously you will need glew source code;) 1) 显然你需要 glew 源代码;)

2) Open glew_shared.dsw files with C::B, edit project properties and, for each build target you need, change it's type from "Dynamic library" to "Static library" (it's right there, at Build targets tab). 2) 使用 C::B 打开 glew_shared.dsw 文件,编辑项目属性,对于您需要的每个构建目标,将其类型从“动态库”更改为“静态库”(它就在那里,在构建目标选项卡上)。 You can also change the destination directory as.dll files are built into bin\ directory.您还可以更改目标目录,因为 dll 文件内置在 bin\ 目录中。

3) Add #define GLEW_STATIC before #include 3) 在#include 之前添加#define GLEW_STATIC

4) Build the target and it will result in proper libglew32*.a being created 4) 构建目标,这将导致创建正确的 libglew32*.a

Further to PoL0's answer, i found those steps did work for me with MinGW on Code::Blocks but with one further alteration required - the default project has a lot of microsoft nonsense set in the "other options" under compiler options.对于 PoL0 的回答,我发现这些步骤确实适用于 MinGW on Code::Blocks,但需要进一步更改——默认项目在编译器选项下的“其他选项”中设置了很多微软的废话。 Clear these and you'll have a good result (project build options -> [each target] -> compiler settings tab -> other options subtab)清除这些,你会得到一个好的结果(项目构建选项 -> [每个目标] -> 编译器设置选项卡 -> 其他选项子选项卡)

You may also wish to enable optimisation for the two release targets (-O2 or -O3).您可能还希望为两个发布目标(-O2 或 -O3)启用优化。

Additionally, the static libraries will be built in "bin" by default, you'll need to copy / move them to replace the ones in "lib".此外,static 库将默认构建在“bin”中,您需要复制/移动它们以替换“lib”中的库。

Here is how VLC builds glew (static) on mingw:以下是 VLC 如何在 mingw 上构建 glew(静态):

https://github.com/videolan/vlc/tree/master/contrib/src/glew (they apply that patch).https://github.com/videolan/vlc/tree/master/contrib/src/glew (他们应用了那个补丁)。 Guess glew has no easy option to "just" build a static library so you have to go through various hurdles (or manually compile, as the other answers allude to).猜猜 glew 没有简单的选择来“只”构建一个 static 库,所以你必须 go 通过各种障碍(或手动编译,正如其他答案所暗示的那样)。

See also http://en.wikibooks.org/wiki/OpenGL_Programming/Installation/Windows#GLEW另见http://en.wikibooks.org/wiki/OpenGL_Programming/Installation/Windows#GLEW

and step 7 here:http://sujatha-techie.blogspot.com/2008/10/glsl-with-mingw.html和第 7 步:http://sujatha-techie.blogspot.com/2008/10/glsl-with-mingw.html

This is how mx does it: https://github.com/mxe/mxe/blob/master/src/glew.mk (looks like they basically just manually build everything, glew's Makefile seems weak...) mx 是这样做的: https://github.com/mxe/mxe/blob/master/src/glew.mk (看起来他们基本上只是手动构建一切,glew 的 Makefile 似乎很弱......)

if you have MingW installed just run Msys and make and make install there once you finish copy the libs and include folders to the bin libs and include folders in MingW and it should all work fine如果您安装了 MingW,只需运行 Msys 并在那里进行安装,一旦您完成复制库并将文件夹包含到 bin 库中并在 MingW 中包含文件夹,它应该一切正常

simple and fast solution简单快速的解决方案

I believe the main Glew website has a link to the binaries on the front page, for 32-bit and 64-bit windows systems.我相信主要的Glew 网站在首页上有一个指向二进制文件的链接,适用于32 位64 位windows 系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM