Building GLEW on Windows with MinGW
Attempting to build GLEW on Windows with MinGW using the command gcc -static glew.c glewinfo.c visualinfo.c -I/path/to/glew/include may result in numerous linker errors due to missing references.
Instead, the appropriate command to build GLEW is as follows (modified from the make log for clarity):
Define GLEW Properties and Compile GLEW
mkdir lib/ mkdir bin/ gcc -DGLEW_NO_GLU -O2 -Wall -W -Iinclude -DGLEW_BUILD -o src/glew.o -c src/glew.c
Build Shared Library (DLL)
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 Static Library
ar cr lib/libglew32.a src/glew.o
Create Pkg-Config File (Optional)
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
Build MEX Version of GLEW
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 Pkg-Config File for MEX Version (Optional)
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
Build Utility Programs (Optional)
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
Following these steps should result in a successful build of GLEW and its associated executables and libraries into the lib and bin folders.
The above is the detailed content of How to Build GLEW on Windows with MinGW?. For more information, please follow other related articles on the PHP Chinese website!