Compile and use FLTK in Windows Environment
May 11, 2025Pre-Requisites
To compile the FLTK library and use it within Windows…
💡 Once WinLibs is extracted, ensure the full path to ming64/bin
is in your PATH
environment variable in Windows. It’s a good idea to test in a command prompt to see if gcc
and cmake
are found correctly.
Compiling FLTK in Windows
Navigate to the source directory for your FLTK download and run:
$ cmake -B build
$ cmake --build build
This will create a build
folder, and in the lib folder will be *.a
files (Unix-like static libraries). Even though this is in Windows, these unix-like static libraries can be linked against with the WinLibs tools to create a Windows executable (.exe
).
Next move the headers (*.h
files) from the FL folder in the root directory and into the build
folder.
Compiling an FLTK Windows Program
Lastly, to compile your C++ program which uses FLTK, run the below - of course first changing the folder paths to suit!
$ g++ -I C:\fltk-1.4.3 -L C:\fltk-1.4.3\lib -o myapp sample.cpp -lfltk -luser32 -lgdi32 -lole32 -lcomctl32 -mwindows -lws2_32 -luuid -lgdiplus -lwinspool
It’s a little unfortunate so many things need to be linked against, such as winspool
(a component of the Windows operating system responsible for managing print jobs) which is hardly relevant in 2025.
It’s likely one could build FLTK so that you can avoid linking everything but the kitchen sink, but that’s a problem for another day.
Bonus: Linux Cross-Compile
You can compile a Windows FLTK application In linux using x86_64-w64-mingw32-g++
$ sudo apt-get update
$ sudo apt-get install mingw-w64
However you must first build a new copy of the FLTK library using mingw
. You can’t just use the copy from your Linux distribution package manager. So find a working directory (ie. somewhere in your /home
), and perform:
$ wget https://www.fltk.org/pub/fltk/1.3.5/fltk-1.3.5-source.tar.gz
$ tar -xzf fltk-1.3.5-source.tar.gz
$ cd fltk-1.3.5
$ ./configure --host=x86_64-w64-mingw32 --build=x86_64-linux-gnu
$ make
There’s no need to run make install
, we will just tell x86_64-w64-mingw32-g++
where to look.
And finally, to cross-compile your FLTK application:
$ x86_64-w64-mingw32-g++ gui.cpp -o gui.exe -I/home/foo/fltk-1.3.11 -L/home/foo/fltk-1.3.11/lib -lfltk -luser32 -lgdi32 -lole32 -lcomctl32 -mwindows -
lws2_32 -luuid -lgdiplus -lwinspool -static-libgcc -static-libstdc++
You can then run gui.exe
in Wine
to confirm correct behaviour.
✨ Hope this tutorial helps!