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)
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
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.
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
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
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".
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...)
I believe the main Glew website has a link to the binaries on the front page, for 32-bit and 64-bit windows systems.
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
Related
The problem is in the title, I'll try to list what I've already tried and so on below.
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.
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
Now I have freeglut in /c/Users/Owner/root/lib/, /c/Users/Owner/root/include/ and so on. Next up is GLEW, my problem child as far as I can tell.
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 windows 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
and should be run from the "root" 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.
-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.
-DGLEW_STATIC is added for the same reason.
-lwinmm is added to fix the linker error: freeglut_init.c:(.text+0x5d9): undefined reference to '_timeBeginPeriod#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'
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);
}
Ideas?
Try adding -lopengl32 last on the line to compile your program and see if it helps.
Argument order is significant with gcc linker options.
Try this:
${G++} -DFREEGLUT_STATIC -DGLEW_STATIC -m32 main.cpp -o main.exe -I ${ROOTPATH}/include -L ${ROOTPATH}/lib -lopengl32 -lwinmm -lgdi32 -lglew32 -static -lfreeglut_static
Also, I don't think there's a double-dash --static option, just -static.
And on win32 you're going to need a successful glewInit() before your glEnableVertexAttribArray() function pointer will be valid. After checking your core version and/or extension, of course :)
This question already has answers here:
Building glew on windows with mingw
(8 answers)
Closed 3 years ago.
I'm a daft C/C++ novice using Windows, building with MinGW through console. I have been looking for days on how to build GLEW so that I can statically link it with my incredibly simple SDL+OpenGL program. For static linking, GLEW supposedly requires a special lib apart from lglew32 called lglew32s, and this is what I cannot get my hands on.
I'm trying to learn to use gcc/g++ right now, and to understand the options and the whole preprocess/compile/link thing in general. I'm about 5% there. I found some GLEW building batch file examples around the net, most being pretty old, but even one of them that was new didn't compile lglew32s for me, so I can dynamically link but I can't statically link.
So because I can't find glew32s.lib anywhere online built with anything other than VS, I have to learn to understand what this means and somehow figure out how to compile glew32s with what I've learned from it:
gcc.exe -DGLEW_NO_GLU -O2 -Wall -W -Iinclude -DGLEW_BUILD -o src/glew.o -c src/glew.c
gcc.exe -fno-builtin -fno-stack-protector -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 -nostdlib
ar.exe cr lib/libglew32.a src/glew.o
gcc.exe -DGLEW_NO_GLU -DGLEW_MX -O2 -Wall -W -Iinclude -DGLEW_BUILD -o src/glew.mx.o -c src/glew.c
gcc.exe -fno-builtin -fno-stack-protector -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 -nostdlib
ar.exe cr lib/libglew32mx.a src/glew.mx.o
I have learned to compile my own .cpp and .c projects using gcc/g++ (again I'm barely out of the "hello world" phase in terms of actual code), and also how to dynamically link them to the SDL and GLEW libraries. I understand very well now what this all means:
g++ sdlglew.cpp -o sdlglew -Wall -lmingw32 -lSDL2main -lSDL2 -lglew32 -lopengl32 -I "C:\SDL2-2.0.9\i686-w64-mingw32\include\SDL2" -L "C:\SDL2-2.0.9\i686-w64-mingw32\lib" -mwindows
(My SDL stuff is off in its own directory. GLEW's headers and libs are in MinGW's dir)
I think I need either -DGLEW_STATIC in my command OR #define GLEW_STATIC in my sdlglew.cpp to compile GLEW statically, but those options with lglew32 give me no errors upon compile and fail to start due to the missing glew32.dll. Compiler spits out errors with -static because SDL has not been set up for it yet.
Basically, if you have any resources on understanding what exactly the mentioned compile script is doing per line and how I could build glew32s, I'd be real happy :S I want to understand it, but it really seems like there's no documentation on it for us newbies
Can't you use the Makefile? (It should be included in the MinGW evironment, I think)
In which case I think you should just be able to do something along the lines of:
cd thefolderwithmakefile
make all GLEW_STATIC=1
Then you need to define GLEW_STATIC ( as you said by -DGLEW_STATIC or by #define GLEW_STATIC )when you are building your project files as well.
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.
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.
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't get it work in that way try mine (for Borland compilers):
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)
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
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,....
Now it should work
do not forget to call glewInit(); after OpenGL is initialized and before any extension is used ...
The problem is in the title, I'll try to list what I've already tried and so on below.
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.
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
Now I have freeglut in /c/Users/Owner/root/lib/, /c/Users/Owner/root/include/ and so on. Next up is GLEW, my problem child as far as I can tell.
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 windows 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
and should be run from the "root" 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.
-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.
-DGLEW_STATIC is added for the same reason.
-lwinmm is added to fix the linker error: freeglut_init.c:(.text+0x5d9): undefined reference to '_timeBeginPeriod#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'
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);
}
Ideas?
Try adding -lopengl32 last on the line to compile your program and see if it helps.
Argument order is significant with gcc linker options.
Try this:
${G++} -DFREEGLUT_STATIC -DGLEW_STATIC -m32 main.cpp -o main.exe -I ${ROOTPATH}/include -L ${ROOTPATH}/lib -lopengl32 -lwinmm -lgdi32 -lglew32 -static -lfreeglut_static
Also, I don't think there's a double-dash --static option, just -static.
And on win32 you're going to need a successful glewInit() before your glEnableVertexAttribArray() function pointer will be valid. After checking your core version and/or extension, of course :)
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)
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
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.
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
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
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".
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...)
I believe the main Glew website has a link to the binaries on the front page, for 32-bit and 64-bit windows systems.
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