Using FLTK in Visual Studio

Note: for configuring FLTK in Linux environments, please refer to this post.

1. Download and extract FLTK

For this particular install I used an old Visual Studio 2003 .NET version. Get the zipped file from the download section of Bill Spitzak’s FLTK site. Unzip the file and place it somewhere suitable such as C:\fltk-1.1.10-source.

In the folder location C:\fltk-1.1.10-source\fltk-1.1.10\visualc\ open the project file called “fltk.dsw”. Once opened, right-click on the project folder called “fltk” and build it. Once successfully built you can then close this project.

2. Configure your Visual Studio Project

Create a new empty project. In the Project properties you will need to make sure the additional include directories have been added. In Project Properties, select C/C++ -> General tab -> Additional Include Directories and enter the path where you installed the fltk folder:

In the Project Properties -> Linker -> Input -> Additional Dependencies, ensure the {fltkd, wsock32, comctl32}.lib libraries have been included. Also ensure that the “Ignore Specific Library” field contains “libcd”.

In Project Properties -> Linker -> General -> Additional Library Directories, ensure the correct path for the fltk library files is given:

In Project Properties -> C/C++ -> Code Generation -> Runtime Library field, make sure the “Multi-threaded Debug DLL (/MDd)” field is chosen:

3. Try it.

You should now be in a position to try a simple example. In your empty project, right-click the Source Files folder and choose to add a new new C++ source file, using “Add New Item”:

and call it main.cpp (say). You should now be able to compile and run this following simple “Hello World!” example:

    #include <FL/Fl.H>  
    #include <FL/Fl_Window.H>  
    #include <FL/Fl_Box.H>  
      
    int main(int argc, char **argv)   
    {  
      Fl_Window *window = new Fl_Window(300,180);  
      Fl_Box *box = new Fl_Box(20,40,260,100,"Hello, World!");  
      box->box(FL_UP_BOX);  
      box->labelsize(36);  
      box->labelfont(FL_BOLD+FL_ITALIC);  
      box->labeltype(FL_SHADOW_LABEL);  
      window->end();  
      window->show(argc, argv);  
      return Fl::run();  
    }  



Update: 16:01 15 April 2012

Some additional insights from Fransiska Putri Wina Menulis and Soeren Theodorsen in the comment sections below. In particular, see Soeren’s comments on getting rid of the DOS prompt if desired.

`