3

It is a duplicate and I am sorry about it but I don't have any other options because I can't make comments on answers and they didn't solved my problem. Here is the original post:

Building glew on windows with mingw

And here is my problem:

1) When I try @LightningIsMyName's answer I get this error:

Makefile:1: *** missing seperator. Stop.

2) When I try @anon's answer I get this error:

Makefile:1: Makefile:1: *** commands commence before first target. Stop.

People says this andswer helped them but they didn't worked for me. I apogilize I duplicae a question somehow but I have no other chance with reputation limit for commenting. Hope you help. Thanks.

Community
  • 1
  • 1
Arda Kara
  • 501
  • 6
  • 24

3 Answers3

9

I have performed many searches in order to find an answer to my problems. It took a lot of time so I am posting it here to help others.

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

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

to GLEW's 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.

Finally, if you are using SFML, link SFML libraries before 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.

Arda Kara
  • 501
  • 6
  • 24
  • 3
    You are a legend. Worked perfectly. – K_Finlay Feb 10 '15 at 08:41
  • I am happy to be helpful – Arda Kara Feb 10 '15 at 11:06
  • Why is an mx version and a non mx version with the same size? Should I link them both? – Shambhav Mar 05 '21 at 12:26
  • @ShambhavGautam unfortunately I am no longer using Windows nor SFML. I went through my archives but couldn't find the project files. – Arda Kara Mar 06 '21 at 13:50
  • @ArdaKara No problem, it is way easier to use GLAD instead, I just downloaded the source and built it and done, no complex linking or dynamic mess, everyone is recommended to use GLAD in case MinGW is being used. Btw the way you wrote as if the only library to use OpenGl is SFML is so weird. – Shambhav Mar 06 '21 at 15:39
  • @ShambhavGautam My problem was also related with SFML, that is why I assumed you are also using SFML. Let me also update my answer. – Arda Kara Mar 07 '21 at 14:08
  • @ArdaKara Your answer has information without giving the reason, like "Put the dll files in system32", no reason given. You can just put it with the exe. Also, you say, GLEW website but don't link it. You say to put gcc.exe in the source, that's neither necessary, neither good, the correct way is to add mingw_location\bin to the path variable or give the full path to gcc.exe. Just update the answer please. Imagine how many beginners are being misinformed due to this. – Shambhav Mar 07 '21 at 14:35
2

If you can't 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 ...

Spektre
  • 49,595
  • 11
  • 110
  • 380
  • I have tried this but it didn't helped me. But I found a solution on net and build glew for MinGW but now it give a linker error. I still can't make OpenGL run after 3 days :( – Arda Kara Jul 19 '14 at 11:46
  • @Senhor you have problems with OpenGL or GLEW? because GLEW does not work propperly without initialized OpenGL contexts prior to glewInit(); so first try to create basic app with OpenGL and no GLEW (OpenGL 1.0) and only after that work add GLEW ... something like this: http://stackoverflow.com/a/20679773/2521214 – Spektre Jul 19 '14 at 16:02
  • I don't know why but my OpenGL didn't worked without GLEW so I installed it. Then I solved the linker error the problem is linking order. Now it Works well. Thanks for your help. – Arda Kara Jul 20 '14 at 13:43
2

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

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207