FLTK Tutorial
Richard Yu Gu
September, 1999
CS 638 Graphics
Instructor: Dr. Gleicher
TA: Richard Yu Gu
Updated September 2000, Michael Gleicher
Last modified: 17:12 Sep 7, 2001
1 Introduction
The Fast Light Tool Kit ("FLTK", pronounced "fulltick") is a LGPL'd
C++ graphical user interface toolkit for X (UNIX®), OpenGL®, and
Microsoft® Windows® NT 4.0, 95, 98, or 2000.
This tutorial shows how to construct GUI applications using FLTK with
Microsoft Visual C++ 6.0.
This tutorial documentation is intended for the reader to quickly get
started with FLTK library under MSVC++ for the Graphics class. Note:
This is neither a detailed or complete documentation for the FLTK library
or MSVC++. Instead, it walks you through the process of building
a program with fltk in the U. Wisconsin CSL software environment.
For the complete documentation please check at http://www.fltk.org/,
or locally at S:\fltk\i386_win2k\documentation\.
Since this documentation is intended for the students in the Graphics class
only, we assume that you are using the instructional Windows 2000 stations
in the CSL labs.
2 Creating A New FLTK Work Space In Visual C ++ 6.0
-
Open Microsoft Visual C++ 6.0 application, by selecting from Start->Programs->Microsoft
Visual C++ 6.0 [or Microsoft Visual Studio 6.0]->Microsoft Visual C++ 6.0.
-
Choose File->New...
-
On top of the dialog box, click on the "Projects" Tab.
-
Select "Win32 Console Application" option. (This is important if
you want to use some standard I/O for debugging)
-
Choose a location and name for the new project.
-
Enable "Create new workspace" ( assume that you are creating a brand new
project )
-
Click "Ok"
-
Choose in the next dialog the option "An empty project".
-
Click "Finish".
-
Click "Ok" in the next dialog
This process should create a new directory with "name" at your specified
location containing the project files, and open the project up in the MSVC++
program.
Note: One big advantage of FlTk over some of the other UI toolkits is
that it can be built into a console application. That means that all of
the C++ standard I/O stuff you used under Unix (like printf or cout) can
be used in your programs.
3 Setting-Up the FLTK project
Now the new project is created, we are going to configurate it to be
a FLTK project.
-
Select Project->Settings...
-
Choose "All Configurations" option in "Settings For:" menu.
-
Click "C/C++" tab, this should bring up the C/C++ compiler page up.
-
Choose "Preprocessor" page from "Category" menu
-
In the field "Additional include directories:", type in: s:\fltk\include
this tells the compiler where the header files for the library are.
-
Click "Link" tab, this should bring up the linker page.
-
Under "Category" menu, select "Input"
-
In the "Additional library path:" field, type in: s:\fltk\lib
this allows the linker to find FLTK library binary files.
The
following steps will set the project, so that correct output format is
used when generating object files.
-
Click "C/C++" tab again
-
Choose "Code Generation" in the "Category" menu
-
Select "Win32 Release" item, in the "Settings For:" menu
-
Change "Use run-time library" option to "Multithreaded DLL" by selecting
it from the menu.
-
Select "Win32 Debug" item, in the "Settings For:" menu
-
Change "Use run-time library" option to "Debug Multithreaded DLL"
by selecting it from the menu.
Then
we need to tell the linker to use the essential librarys when creating
the executable file. Notice that we must change the settings for both "Debug"
and "Release" versions. For debug, we need to specify the debug version
of the fltk library. Also, notice that we are adding the 2 libraries to
our program, so we must be careful not to remove any others.
-
Click "Link" tab
-
Select "Win32 Release" item, in the "Setting For:" menu
-
Add WITHOUT replacing anything else in the "Object/library modules:" field
the following text: fltk.lib wsock32.lib
-
Select "Win32 Debug" item, in the "Setting For:" menu
-
Add WITHOUT replacing anything else in the "Object/library modules:" field
the following text: fltkd.lib wsock32.lib
-
Then click "Ok".
4 Create and Add Source Files The The Project
After you have all the options setup, the project is FLTK ready.
All you need is to add your FLTK source files to the project, then build
and run.
To add source files to the project, you need to follow the following
instruction.
-
Choose Project->Add To Project->Files....
-
You should see a file-selection dialog appears. Select the files
that you want to add to the project. You can select multiple files
in the same directory by holding down Ctrl key and click the file name.
-
Click Ok.
One working example program source code is here.
You can try this file first to make sure that all the options for the project
is setup correctly.
There is a working example project here.
You can use the settings of this project as a template for our programs.
For more FLTK code examples please refer to the FAQ of this tutorial.
5 Build And Run
Choose Build->Build [projectname].exe.
Now choose Build->Execute [projectname].exe
This should compile and link this project, and launch the new executable.
If during Build process, error messages are generated, then there might
be some problem with either your code or some settings that we have done.
For more detail please refer to Trouble Shooting.
If the errors occur at other places, most likely the problem is in your
program code itself.
Note: You can choose to build and run the project in either Debug or
Release configuration by choosing the desired option through Build->Set
Active Configuration... menu.
6 Reopen A Project
The easiest way to do so is to go to the project directory and double-click
on the [projectname].dsw file.
Or you can choose File->Open WorkSpace within the MSVC application,
and open the [projectname].dsw file.
7 FLTK Basics
-
Include Standard
The FLTK standard for library include files is to include the file with
FL/ path correct in the file name.
For example, if you need to use Fl_Window object, then you should have
this line in your code:
#include <FL/Fl_Window.H>
Appendix A. Trouble Shooting.
-
Error that indicate FLTK library include/header file (.h files) not found
during compilation
You did not set the "Directories" "Include Files" path correctly
for the FLTK library, refer to steps 3.3-3.5
-
Error that indicate unresolved function definitions, or error during linking
process
-
You did not correctly add the fltkd.lib wsock32.lib to the "Link" option
in the Project->Setting, refer to steps 3.15-3.19
-
You did not correctly set the path for the library files for FLTK, refer
to steps 3.6-3.8
-
Other compile errors
Most likely caused by some problem in your code.
-
Error/Crash during the execution of your program
Most likely caused by some problem in your code.
-
The linker complains:
LINK : warning LNK4098: defaultlib "LIBCMTD" conflicts with use of other
libs; use /NODEFAULTLIB:library
This means that you did not compile your program with the correct code
generation settings, described above, refer to steps 3.9-3.14
Appendix B FAQ
-
Are there any FLTK examples program we can check out to get a feel for
the library?
-
There are examples at S:\fltk\src\fltk-1.0.11\test.
-
and the Project Workspace file is at S:\fltk\src\fltk-1.0.11\visualc\fltk.dsw
To be updated when more questions come up.