FLTK/Basic applications

Basic window source code


Here is the smallest FLTK application, it shows an empty window:

#include <fltk/run.h>
#include <fltk/Window.h>

int main (int argc, char** argv) {

	// build a square window (with a side of 300 pixels)
	fltk::Window window (300, 300, "FLTK test");

	// show it
	window.show (argc, argv);

	// enter the FLTK event loop
	return fltk::run();

Compiling and running this piece of code yields the following kind of window:

GNU Linux screen shot
Mac OS X screen shot

Basic application compilation


To build above code, first save it to a file named test.cxx. You can also use test.cpp, but the cxx extension is the one used by FLTK source code.

We assume GCC is installed, since it is required to build FLTK. Depending on the environment, windowing system libraries need to be linked against the executable. Basically, the following command is the minimum required to build test.cxx:

g++ -o test test.cxx -lfltk2

Using the X Window system (GNU Linux for example), you usually need to add the following ones:

g++ -o test test.cxx -lfltk2 -lXi -lXinerama -lXft

Under Mac OS X, you'll have to link with the Carbon framework:

g++ -o test test.cxx -lfltk2 -framework Carbon