Programming: Principles and Practice Using C++ (2014)

Part V: Appendices

D. Installing FLTK

“If the code and the comments disagree,
then both are probably wrong.”

—Norm Schryer

This appendix describes how to download, install, and link to the FLTK graphics and GUI toolkit.


D.1 Introduction

D.2 Downloading FLTK

D.3 Installing FLTK

D.4 Using FLTK in Visual Studio

D.5 Testing if it all worked


D.1 Introduction

We chose FLTK, the Fast Light Tool Kit (pronounced “full tick”), as the base for our presentation of graphics and GUI issues because it is portable, relatively simple, relatively conventional, and relatively easy to install. We explain how to install FLTK under Microsoft Visual Studio because that’s what most of our students use and because it is the hardest. If you use some other system (as some of our students also do), just look in the main folder (directory) of the downloaded files (§D.3) for directions for your favorite system.

Whenever you use a library that is not part of the ISO C++ standard, you (or someone else) have to download it, install it, and correctly use it from your own code. That’s rarely completely trivial, and installing FLTK is probably a good exercise — because downloading and installing even the best library can be quite frustrating when you haven’t tried before. Don’t be too reluctant to ask advice from people who have tried before, but don’t just let them do it for you: learn from them.

Note that there might be slight differences in files and procedures from what we describe here. For example, there may be a new version of FLTK or you may be using a different version of Visual Studio from what we describe in §D.4 or a completely different C++ implementation.

D.2 Downloading FLTK

Before doing anything, first see if FLTK is already installed on your machine; see §D.5. If it is not there, the first thing to do is to get the files onto your computer:

1. Go to http://fltk.org. (In an emergency, instead download a copy from our book support website: www.stroustrup.com/Programming/FLTK.)

2. Click Download in the navigation menu.

3. Choose FLTK 1.1.x in the drop-down and click Show Download Locations.

4. Choose a download location and download the .zip file.

The file you get will be in .zip format. That is a compressed format suitable for transmitting lots of files across the net. You’ll need a program on your machine to “unzip” it into normal files; on Windows, WinZip and 7-Zip are examples of such programs.

D.3 Installing FLTK

Your main problem in following our instructions is likely to be one of two: something has changed since we wrote and tested them (it happens), or the terminology is alien to you (we can’t help with that; sorry). In the latter case, find a friend to translate.

1. Unzip the downloaded file and open the main folder, fltk-1.1.?. In a Visual C++ folder (e.g., vc2005 or vcnet), open fltk.dsw. If asked about updating old project files, choose Yes to All.

2. From the Build menu, choose Build Solution. This may take a few minutes. The source code is being compiled into static link libraries so that you do not have to recompile the FLTK source code any time you make a new project. When the process has finished, close Visual Studio.

3. From the main FLTK directory open the lib folder. Copy (not just move/drag) all the .lib files except README.lib (there should be seven) into C:\Program Files\Microsoft Visual Studio\Vc\lib.

4. Go back to the FLTK main directory and copy the FL folder into C:\Program Files\Microsoft Visual Studio\Vc\include.

Experts will tell you that there are better ways to install than copying into C:\Program Files\Microsoft Visual Studio\Vc\lib and C:\Program Files\Microsoft Visual Studio\Vc\include. They are right, but we are not trying to make you VS experts. If the experts insist, let them be responsible for showing you the better alternative.

D.4 Using FLTK in Visual Studio

1. Create a new project in Visual Studio with one change to the usual procedure: create a “Win32 project” instead of a “console application” when choosing your project type. Be sure to create an “empty project”; otherwise, some “software wizard” will add a lot of stuff to your project that you are unlikely to need or understand.

2. In Visual Studio, choose Project from the main (top) menu, and from the drop-down menu choose Properties.

3. In the Properties dialog box, in the left menu, click the Linker folder. This expands a sub-menu. In this sub-menu, click Input. In the Additional Dependencies text field on the right, enter the following text:

fltkd.lib wsock32.lib comctl32.lib fltkjpegd.lib fltkimagesd.lib

[The following step may be unnecessary because it is now the default.] In the Ignore Specific Library text field, enter the following text:

libcd.lib

4. [This step may be unnecessary because /MDd is now the default.] In the left menu of the same Properties window, click C/C++ to expand a different sub-menu. Click the Code Generation sub-menu item. In the right menu, change the Runtime Library drop-down to Multi-threaded Debug DLL (/MDd). Click OK to close the Properties window.

D.5 Testing if it all worked

Create a single new .cpp file in your newly created project and enter the following code. It should compile without problems.

#include <FL/Fl.h>
#include <FL/Fl_Box.h>
#include <FL/Fl_Window.h>

int main()
{
            Fl_Window window(200, 200, "Window title");
            Fl_Box box(0,0,200,200, "Hey, I mean, Hello, World!");
            window.show();
            return Fl::run();
}

If it did not work:

• “Compiler error stating a .lib file could not be found”: Your problem is most likely in the installation section. Pay attention to step 3, which involves putting the link libraries (.lib) files where your compiler can easily find them.

• “Compiler error stating a .h file could not be opened”: Your problem is most likely in the installation section. Pay attention to step 4, which involves putting the header (.h) files where your compiler can easily find them.

• “Linker error involving unresolved external symbols”: Your problem is most likely in the project section.

If that didn’t help, find a friend to ask.