30

Can anyone give me the correct command to build glew on windows with mingw?

I have tried:

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.

(alternatively if anyone can point me to a windows 32b build i would be very grateful)

  • `gcc -shared -O2 -Wl,--out-implib=libglew.dll.a -o libGLEW.dll -Iinclude -DGLEW_BUILD glew.c` –  May 06 '15 at 05:17

8 Answers8

49

To build it with MinGW, you should do (copied from the make log, with slight modifications and additional explanations):

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

Barak Itkin
  • 4,872
  • 1
  • 22
  • 29
  • This seems to have solved my errors, but it's worth noting that glew32.dll showed up in the lib folder rather than the bin folder (which was empty). Maybe I should have run it line-by-line on the command line rather than putting it in a .bat file, but as I said, it seemed to work. – player_03 Feb 19 '13 at 16:35
  • I'm getting following errors `libglew32.dll: No such file or directory` `lib/libglew32.dll.a: No such file or directory` `unrecognized option -soname` `unrecognized option --out-implib`, any idea why? – jtomaszk Jun 14 '13 at 11:04
  • 1
    OK, I have no idea that I was suppose to run it under MSYS - it works – jtomaszk Jun 14 '13 at 11:20
  • Tested this on Windows 7 with MingW32 and it worked, thank you! – Bunkerbewohner Sep 01 '13 at 10:45
  • 9
    This totally works, thank you. Why don't the GLEW developers so much as hint towards this? Windows == VS for them. – Adrian Feb 09 '14 at 22:20
  • @Adrian as far as a lot of people are concerned VS is Windows. There was a time when I was pro VS until one day I was told "We want it to be cross compatible. VS was not designed with cross compatibility in mind if you ask me but saying that VS is a very good tool. – PurityLake Jun 19 '14 at 14:42
  • 1
    i had to use -nostdlib in front of -shared in the 2 instruction containing gcc -shared to make it work with msys – seb_kaine Mar 29 '17 at 08:30
19

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:

    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.

anon
  • 191
  • 1
  • 2
  • 1
    When the second command fails with a DllMainCRTStartup error, see https://stackoverflow.com/a/38729847/ for addendum. – Kevin Yin Dec 02 '17 at 12:11
6

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.

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:

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

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
Jérôme Pouiller
  • 9,249
  • 5
  • 39
  • 47
6

Found another solution that works with Code::Blocks. Steps:

1) Obviously you will need glew source code ;)

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.

3) Add #define GLEW_STATIC before #include

4) Build the target and it will result in proper libglew32*.a being created

PoL0
  • 101
  • 1
  • 6
1

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)

You may also wish to enable optimisation for the two release targets (-O2 or -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".

Riot
  • 15,723
  • 4
  • 60
  • 67
1

Here is how VLC builds glew (static) on mingw:

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

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

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

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
0

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

simple and fast solution

hopjopper
  • 99
  • 8
0

I believe the main Glew website has a link to the binaries on the front page, for 32-bit and 64-bit windows systems.

Barak Itkin
  • 4,872
  • 1
  • 22
  • 29
  • 3
    only for visual C++. I tried 'reimp' to convert the .lib to .a files but it says they are invalid –  May 14 '11 at 22:23
  • apparently mingw can link against their dll's, ref: http://en.wikibooks.org/wiki/OpenGL_Programming/Installation/Windows#GLEW – rogerdpack Sep 17 '13 at 03:41