Building FreeGlut 3.0.0 with MinGW on Windows 8.1
Downloading the Compiler and FreeGlut sources
- Download the MinGW and MSYS installer (usually called mingw-get-setup.exe) from here (SourceForge)
- Download the FreeGlut source from here
Setting our environment variables
- Make sure the MinGW bin directory is the FIRST DIRECTORY listed on your System Environment Variable
- Completing the above process will help you avoid any possible conflicts during the build process
Extraction and building
- If you don't know how to extract a tar.gz file, install either 7-Zip or WinRAR
- Now remove the android, blackberry, egl, osx and x11 folders from the src folder.
- You'll also want to remove the freeglutdll.def.in file, plus the fg_version.h.in and gles_stub.c files
- The reason why we deleted the above folders and files is because they aren't required in the Windows build process
- Now open a command prompt and cd to the mswin directory
Creating a shared library
- A shared library means that you will have to distribute a dll with your program
- From the mswin directory copy and paste the following into the command prompt
gcc -w -O2 -c -D_WIN32_WINNT=0x0500 -DWINVER=0x0500 -D_CRT_SECURE_NO_WARNINGS -DNEED_XPARSEGEOMETRY_IMPL -DFREEGLUT_EXPORTS -I..\..\include *.c ..\*.c ..\util\*.c
- It should build without any warnings and errors
- Now it's time for the linking process, copy and paste the following into the command prompt
gcc -mdll -o freeglut.dll *.o -Wl,--enable-stdcall-fixup,--out-implib,libfreeglutdll.a -lopengl32 -lwinmm -lgdi32 -lm
Creating a static library
- A program built using a static library won't have any dll dependencies
- From the mswin directory copy and paste the following into the command prompt
gcc -w -O2 -c -D_WIN32_WINNT=0x0500 -DWINVER=0x0500 -D_CRT_SECURE_NO_WARNINGS -DNEED_XPARSEGEOMETRY_IMPL -DFREEGLUT_STATIC -I..\..\include *.c ..\*.c ..\util\*.c
- The linking for the static library is a lot easier than the shared version
ar -rcs libfreeglut.a *.o
Placement of files
- Your compiler is usually located at C:\MinGW
- Place freeglut.dll in the bin directory located at C:\MinGW\bin
- Place libfreeglut.a and libfreeglutdll.a in the lib directory located at C:\MinGW\lib
- Finally place freeglut.h freeglut_ext.h freeglut_std.h and glut.h in the include directory located at C:\MinGW\include\GL
Compiling an example
- If you look in the freeglut demos directory you'll see an example called Fractals
- Navigate to the above folder and decide whether you want to create a shared or static build
Fractals shared build
- Remember you'll need to distribute the freeglut.dll with it
gcc -c -O2 fractals.c -DFREEGLUT_EXPORTS
gcc -o fractals.exe *.o -lfreeglutdll -lopengl32 -mwindows
Fractals static build
- To build the example statically
gcc -c -O2 fractals.c -DFREEGLUT_STATIC
gcc -o fractals.exe *.o -lfreeglut -lopengl32 -lwinmm -gdi32 -mwindows