What Happens When I Build QB64?

This is my attempt to understand what happens when one builds QB64 on Windows. We initiate the build process by running setup_win.bat in the root level of the qb64 source repository, so this seems like a good place to dive in.

Delete Files

Our first step is to delete all files in the internal\c\libqb\ and internal\c\parts\ folders with the extensions .o and .a. In addition we delete all files in the internal\temp\ folder.

Extract C++ Compiler

Our second step is to extract the C++ compiler contained in internal\c\c_compiler if this has not already been done.

Build LibQB

We follow this up by moving into the internal\c\libqb\os\win\ folder where we delete any existing libqb_setup.o file and then kick off another build using setup_build.bat. This file kicks off another compilation by g++ with the following options:

  • -c
  • -w
  • -Wall
  • libqb.cpp
  • -o libqb_setup.o

-D allows us to include or exclude compiler directives from being executed during a build. Why would we want to do this? Depending on what we are building we may not require only some of the dependencies and not others, this helps us avoid using compiler directives that aren’t necessary for our specific build.

Build FreeType

We do something very similar with FreeType at internal\c\parts\video\font\ttf\os\win, deleting src.o if it exists and kicking off setup_build.bat. This file again kicks off a compilation by g++ with the following options:

  • -c
  • -w
  • -Wall
  • ..\..\src\freetypeamalgam.c
  • -o src.o

Build Core:FreeGLUT

Similarly, we move into internal\c\parts\core\os\win, deleting src.a if it exits and kicking off setup_build.bat. This in turn runs gcc on a number of files with the associated options listed below:

  • -s -O2 -c ..\..\freeglut_callbacks.c -o temp\freeglut_callbacks.o
  • -s -O2 -c ..\..\src\freeglut_cursor.c -o temp\freeglut_cursor.o
  • -s -O2 -c ..\..\src\freeglut_display.c -o temp\freeglut_display.o
  • Are you seeing a pattern? It continues in the same manner for freeglut_ext.c, freeglut_font.c, freeglut_font_data.c, freeglut_gamemode.c, freeglut_geometry.c, freeglut_glutfont_definitions.c, freeglut_init.c, freeglut_input_devices.c, freeglut_joystick.c, freeglut_main.c, freeglut_menu.c, freeglut_misc.c, freeglut_overlay.c, freeglut_spaceball.c, freeglut_state.c, freeglut_stroke_mono_roman.c, freeglut_stroke_roman.c, freeglut_structure.c, freeglut_videoresize.c, freeglut_window.c, freeglut_xinput.c
  • Then it runs c_compiler\bin\ar rcs src.a temp\freeglut_callbacks.o temp\freeglut_cursor.o and so on, e.g., if you notice this is now running all of the files generated above.

Build QB64

Finally, we get to building QB64 itself. We accomplish this through the following steps:

  • Copying all files in internal\source\ into internal\temp\
  • Copying source\qb64.ico and source\icon.rc into internal\temp\
  • From the internal\c kick off c_compiler\bin\windres.exe
    • -i ..\temp\icon.rc -o ..\temp\icon.o
  • From the internal\c folder kick off c_compiler\bin\g++
    • Instructs that a console application is to be created: –mconsole
    • Removes all symbol table and relocation info. from resultant executable: -s
    • Abort compilation on first error, don’t continue attempting to compile: -Wfatal-errors
    • Suppress all warnings: -w
    • Turn on all optional warnings (-Wcomment, -Wtrigraphs, and Wmultichar) -Wall
    • qbx.cpp
    • libqb\os\win\libqb_setup.o
    • ..\temp\icon.o
    • parts\core\os\win\src.a
    • Link to the OpenGL library: -lopengl32
    • Link to the OpenGL Utility Toolkit (GLUT) using FreeGLUT: -lglu32
    • Instructs compiler to create a GUI app: -mwindows
    • Forces compiler to use static, not shared libgcc: -static-libgcc
    • Forces compiler to use static, not shared libstd++: -static-libstdc++
    • Link to the Windows Winsock library: -lws2_32
    • Link to the Windows Multimedia API: -lwinmm
    • Link to the Windows Graphics Device Interface Library: -lgdi32
    • Output the result of this compilation: -o “..\..\qb64.exe”


I’m sure there are others that I owe thanks to, if you think you are one of them, let me know. For now I’ll just save thanks to Fellippe Heitor who has answered many of my questions.