Home  >  Article  >  Backend Development  >  How to build GLEW on Windows with MinGW? A step-by-step guide.

How to build GLEW on Windows with MinGW? A step-by-step guide.

Barbara Streisand
Barbara StreisandOriginal
2024-10-26 02:12:03497browse

How to build GLEW on Windows with MinGW? A step-by-step guide.

Building GLEW on Windows with MinGW: A Comprehensive Guide

Using GLEW, a header-only library that seamlessly integrates OpenGL and WGL functions, enhances the development of OpenGL applications on Windows using MinGW. To effectively build GLEW with MinGW, a specific set of commands and steps is necessary.

First, create two directories named lib and bin to store the libraries and executables, respectively. Then, compile the GLEW source file with the following command:

gcc -DGLEW_NO_GLU -O2 -Wall -W -Iinclude -DGLEW_BUILD -o src/glew.o -c src/glew.c

Next, build the shared library:

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

This command creates the libglew32.dll shared library and the corresponding import library lib/libglew32.dll.a.

To create a static library, execute the following command:

ar cr lib/libglew32.a src/glew.o

Optionally, to generate a pkg-config file, use the following command:

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

Similarly, build the GLEW MX library and executables using the following commands:

# GLEW MX library
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

# GLEW MX pkg-config file 
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

# GLEW Visualinfo program
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

# GLEW Visualinfo program
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

By following these instructions, you can successfully build GLEW with MinGW on Windows, creating the necessary libraries and executables.

The above is the detailed content of How to build GLEW on Windows with MinGW? A step-by-step guide.. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn