C++ 使用 mingw 在窗户上发光的建筑物
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6005076/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Building glew on windows with mingw
提问by Barak Itkin
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).
但我收到了数千个链接器错误(缺少参考)。
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 版本,我将不胜感激)
回答by Barak Itkin
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 文件夹,其中包含所需的可执行文件和库
回答by anon
I got it working (with MinGW), i didn't compile the glew32mx but glew32 instead. Just download the source .zip from GLEW website. 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:
我让它工作(使用MinGW),我没有编译glew32mx,而是编译glew32。只需从 GLEW 网站下载源 .zip。并且记得在glew-1.xx目录下创建“lib”目录,否则编译下面第二行代码时会报错“can't find /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 编译的。
回答by Jér?me Pouiller
Glew build system try to detect automatically your environment using config/configure.guess
. You may overload this behaviour by specify $SYSTEM
to make. See config/Makefile.*
for all supported build configuration. Glew already include configuration to use MinGW.
Glew 构建系统尝试使用config/configure.guess
. 您可以通过指定$SYSTEM
make来重载此行为。查看config/Makefile.*
所有支持的构建配置。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- I had to specify directory where system libraries was located
- I had to specify where glew should be installed
$CC
并且$LD
不正确- 我必须指定系统库所在的目录
- 我必须指定应该安装 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
回答by PoL0
Found another solution that works with Code::Blocks. Steps:
找到了另一个适用于 Code::Blocks 的解决方案。脚步:
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). You can also change the destination directory as .dll files are built into bin\ directory.
2) 用 C::B 打开 glew_shared.dsw 文件,编辑项目属性,对于您需要的每个构建目标,将其类型从“动态库”更改为“静态库”(它就在那里,在构建目标选项卡上)。您还可以更改目标目录,因为 .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
回答by Riot
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. Clear these and you'll have a good result (project build options -> [each target] -> compiler settings tab -> other options subtab)
除了 PoL0 的回答之外,我发现这些步骤对我在 Code::Blocks 上的 MinGW 确实有效,但需要进一步更改 - 默认项目在编译器选项下的“其他选项”中设置了很多微软废话。清除这些,你会得到一个好的结果(项目构建选项 -> [每个目标] -> 编译器设置选项卡 -> 其他选项子选项卡)
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".
此外,默认情况下静态库将构建在“bin”中,您需要复制/移动它们以替换“lib”中的库。
回答by rogerdpack
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). 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).
https://github.com/videolan/vlc/tree/master/contrib/src/glew(他们应用了那个补丁)。Guess glew 没有简单的选择来“仅”构建一个静态库,因此您必须经历各种障碍(或手动编译,正如其他答案所暗示的那样)。
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 似乎很弱......)
回答by hopjopper
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,只需在完成复制库和包含文件夹到 bin 库并在 MingW 中包含文件夹后运行 Msys 和 make 并在那里进行安装,它应该一切正常
simple and fast solution
简单快速的解决方案