Building glew on windows with mingw32

强颜欢笑 提交于 2019-11-28 08:50:36

I have made too many searching on net to find an answer for my problems. I took a lof ot time so I am posting it here to help others.

To make GLEW work with MinGW you should download source from GLEW website and put

gcc.exe from MinGW\bin
ar.exe from MinGW32\mingw32\bin

to GLEWs source folder and create and run a .bat in that folder like that:

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

you will get your .dll and .a files in lib folder. Put .dll files to system32 folder and put .a files to MinGW lib folder.

While linking link SFML libraries first then link GLEW and at last link OpenGL. If you change the linking order you will get a linker error.

Don't forget to call glewInit() after creating your window.

Try these commands:
1: gcc -DGLEW_NO_GLU -O2 -Wall -W -Iinclude -DGLEW_BUILD -o src/glew.o -c src/glew.c
2: 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
3: ar cr lib/libglew32.a src/glew.o

If you can get it work in that way try mine (for Borland compilers):

  1. download GLEW source code (not the binaries)

    • glew.c source code mine is ~900KB (I think GLEW 1.6)
    • glew.h header mine is ~900KB (I think GLEW 1.6)
  2. I use local project path to store GLEW

    I know it is redundant but I do not need to make changes after system changes like reinstall OS or new compiler version etc... but to get it work you need to do some changes inside glew.c:

    • change #include <glew.h> to #include "glew.h"

    if you want to use global path then add it to your compiler,copy the files there and leave the <> as are

  3. copy these 2 files to your project

    this is how to correctly include it into project just add this to your main source file (where your winmain or main function is):

    #include <windows.h> // optional windows
    #include <math.h>    // optional
    #define GLEW_STATIC  // this configure header and source of GLEW to compile correctly 
    #include "glew.c"    // header is included inside so no need to duplicate include
    // here are the OpenGL includes like: gl.h,glext.h,....
    
  4. Now it should work

    do not forget to call glewInit(); after OpenGL is initialized and before any extension is used ...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!