编译简单的静态OpenGL 4.0程序使用MinGW,freeglut和glew [英] Compiling Simple static OpenGL 4.0 program using MinGW, freeglut and glew

查看:464
本文介绍了编译简单的静态OpenGL 4.0程序使用MinGW,freeglut和glew的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题在于标题,我会尽量列出我已经尝试过的等等。

The problem is in the title, I'll try to list what I've already tried and so on below.

首先,在我的理解,为了在Windows上使用OpenGL 4.0,你必须扩展和或绕过默认的Windows库,因为它只提供OpenGL 1.1。

First off, in my understanding, in order to use OpenGL 4.0 on windows you must extend and or bypass the default windows library as it only ships OpenGL 1.1.

所以我们有MinGW安装在 C:/ MinGW / 。接下来,我通过下载设置FreeGLUT tarball 项目网站。根据说明运行makefiles,并添加少量<$ c,以便提取和编译$ c> - 命令。

So we have MinGW installed at C:/MinGW/. Next I setup FreeGLUT by downloading the tarball from the project site. Extract and compile by running the makefiles according to the instructions with a minor addition of --prefix to the ./configure command.

./configure --prefix=/c/Users/Owner/root/
make all
make install 

现在我在 / c / Users / Owner / root / lib / / c / Users / Owner / root / include / 等。

项目网站 direct 1.7.0.zip link )。编译是一个更复杂,我当前的食谱是从堆栈溢出问题建设mingw 。缩写形式如下:

Download the source archive from the project site (direct 1.7.0.zip link). Compiling is a tad more complicated, my current recipe is derived from the stack overflow question " Building glew on with mingw ". An abbreviated form is listed below:

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
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

of /path/to/glew-1.7.0 /

现在使用库的设置完成(假设没有错误...)编译我的简单程序是用这一行。

Now with setup of libraries "done" (assuming no mistakes... ) compiling my simple program is done with this line.

${G++}  -DFREEGLUT_STATIC -DGLEW_STATIC -m32 main.cpp -o main.exe -lfreeglut_static -lopengl32 -lwinmm -lgdi32 -lglew32  -I ${ROOTPATH}/include -L ${ROOTPATH}/lib --static

现在分解这一点,并且了解为什么我有各种额外参数,

Now to decompose this a bit and walk through why I have various "extra" arguments and to show you what errors and problems I've already run into and solved.


  1. -DFREEGLUT_STATIC 并且使用 -lfreeglut_static 代替正常的 -lfreeglut ,因为我们想要一个静态构建。不这样做会给出与freeglut有关的链接器错误。

  2. -DGLEW_STATIC 是基于同样的原因。

  3. -lwinmm 被添加以修复链接器错误: freeglut_init.c :(。text + 0x5d9):未定义引用'_timeBeginPeriod @ 4'
  4. 添加
  5. -lgdi32 以修复链接器错误: c:/ Users / Owner / root // lib \libfreeglut_static.a(freeglut_init.o):freeglut_init.c :(。text + 0x58c):未定义引用_GetDeviceCaps @ 8

  1. -DFREEGLUT_STATIC and -lfreeglut_static are used instead of the normal -lfreeglut as we want a static build here. Failure to do this gives linker errors relating to freeglut.
  2. -DGLEW_STATIC is added for the same reason.
  3. -lwinmm is added to fix the linker error: freeglut_init.c:(.text+0x5d9): undefined reference to '_timeBeginPeriod@4'.
  4. -lgdi32 is added to fix the linker error: c:/Users/Owner/root//lib\libfreeglut_static.a(freeglut_init.o):freeglut_init.c:(.text+0x58c): undefined reference to '_GetDeviceCaps@8'

现在我遇到以下链接器错误:

Now I'm stumped with the following linker error:

c:/Users/Owner/root//lib\libglew32.a(glew.o):glew.c:(.text+0x83e8): undefined reference to `_glGetString@4'
c:/Users/Owner/root//lib\libglew32.a(glew.o):glew.c:(.text+0xa1b2): undefined reference to `_glGetString@4'
c:/Users/Owner/root//lib\libglew32.a(glew.o):glew.c:(.text+0xa290): undefined reference to `_glGetString@4'


$ b b

产生此错误( main.cpp )的最小测试用例为。

The minimal test case that produces this error (main.cpp) is.

#include <GL/glew.h>
#include <GL/freeglut.h>

int main(int argc, char **argv) {
  glEnableVertexAttribArray(0);
}

想法?

推荐答案

尝试在最后一行添加-lopengl32来编译程序,看看是否有帮助。

Try adding -lopengl32 last on the line to compile your program and see if it helps.

这篇关于编译简单的静态OpenGL 4.0程序使用MinGW,freeglut和glew的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆