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.

Comments

10 responses to “Using FLTK in Visual Studio”

  1. pw Avatar

    If yout get error LNK what you should do is:
    In the Project Properties -> Linker -> Input -> Additional Dependencies, you have to include other library: fltkjpegd.lib, fltkimagesd.lib
    It worked for me

    1. admin Avatar
      admin

      Thanks for the additional info.
      Andy

  2. Soeren Theodorsen Avatar
    Soeren Theodorsen

    Thank you for the great guide!

    If you’re compiling in Visual Studio 6 or 2010 Express and get this error: fltkd.lib(Fl_x.obj) : error LNK2001: unresolved external symbol __imp___TrackMouseEvent@4

    you need to include comctl32.lib (project->settings->link->object/library modules to add it)

    Also, if you do not want a DOS prompt to open, compile the relase build (in step 1 and use fltk.lib instead of fltkd.lib in step 2 and finally specify linker option “/SUBSYSTEM:WINDOWS” in step 3.

    Cheers 🙂
    Søren

    1. Andy Avatar
      Andy

      Some useful insights here. Thanks Soeren.

  3. Mahetab Avatar
    Mahetab

    I’m very new with fltk, i just want to know.
    How should i know which library to add?

    ~M

    1. happyuk Avatar
      happyuk

      Hi Mahetab.
      Some further explanation on what you are doing would definitely help. Are you working in a Visual Studio environment? Or Linux? Have you tried doing what’s on this posting?

      1. Mahetab Avatar
        Mahetab

        Hi,
        I built fltk successfuly on windows using vs2010 to use it as GUI for itk applications but the problem is that i can’t integrate it with itkapps. Any help will be appreciated.

  4. tno2007 Avatar
    tno2007

    thanks a lot, i used your tutwith c-jump.com/bcc/common/Talk2/Cxx/FltkInstallVC/FltkInstallVC.html and it worked awesome

    1. happyuk Avatar
      happyuk

      Lovely stuff.

  5. dwagner Avatar
    dwagner

    Hi all,

    I’m new in FLTK and I have problems executing the very simple „Hello World“ example 🙁

    #include
    #include

    int main()
    {
    // Create a window – width, height, label (=title)
    Fl_Window win(400, 400,”FLTK Tutorial – Example 1″);

    // Display the window
    win.show();

    // Run and return
    return Fl::run();
    }

    My configuration is:
    Win 7 prof
    Eclipse Luna with C++ and MinGW (latest versions)
    FLTK 1.3 – a compiled windows package from https://code.google.com/p/fltkwinbin/downloads/detail?name=fltk-1.3.x-r8627-win-bin.rar&can=2&q=

    I can make an executable without any compiler or linker error, but if I run the executable I get only the message „…exe no longer works“).

    What could be the problem?