Wednesday, 11 March 2020

How To Install FLTK For Use With Programming: Principles & Practice Using C++

There are instructions at the back of the book (page 1204) on how to install FLTK however, these are for use with 1.1.x.

FLTK advises users to no longer use the 1.1.x versions of FLTK anymore as they won't compile on most modern computers. This is true. 1.1.10 would not compile on my pc (some of the files were from 2003...)

Instead of copying the lib files to the VS folders I have documented how I would usually include a library into a project. You can use steps 6 onwards, to include any library. I normally use DirectX9.

1. Download the latest stable release from here:
https://www.fltk.org/software.php

(I usually download the tar.gz version).

I'm using 1.3.5 in these exercises.

EDIT 07/10/2021 - I followed these steps using the latest version of 1.3.7 and it worked fine.
EDIT 12/02/2023 - Followed these step using the latest version of 1.3.8 and works fine.
EDIT 30/04/2024 - Followed these steps using the latest version of 1.3.9 with Visual Studio 2022 and it works fine. I did have to change my build mode to x86 though with VS2022.

2. Unzip the file (you may need to do this twice depending on what zip programs you have installed).

3. Within the FLTK folder, navigate to ide -> VisualC2010 and open the fltk Visual Studio Solution. For me this opened automatically using VS2017.

4. VS will ask you to re-target the solution. Just click ok.


5. Build the solution. This will take a few minutes. When you include FLTK in your solution now, you won't have to recompile the library every time you build. (Building in Win32 Debug mode is fine for debugging. If you want release, build in release). You can then close the solution.

6. Open up the VS solution you wish to work in. Right click on the solution name in the explorer and select properties.


7. Click on VC++ Directories. Click on Include Directories and the arrow that appears on the right and then edit.


8. Click on the new folder icon at the top, then the three dots that appear. Navigate to the folder on your pc where fltk is. Click Select Folder and the press OK.

9. Repeat steps 7 & 8 but with the the Library Directories.


Press Apply and then OK. Normally you would choose the separate folders for each. For example, the include directories would be the include folder and the libraries would be the library folder. However, FLTK itself uses the FL/... structure so if you do this you will find that your program will fail to build with an error like so:

EDIT: I didn't realise I had done this on my own PC until these steps failed to work on my work pc; I had added additional dependencies in Linker. In the Library Directories section, please also include the lib folder of FLTK. Or you can leave it the way it is and add the folder to the additional dependencies like so:


10. Go to the properties again but this time navigate to Linker -> Input -> Additional Dependencies. Click the arrow, then edit and add these on new lines  in the top box (ignore the top one):

Click OK. The on the end of each library is for the debug builds. If you want to build a release version you will need to use different libraries.

Edit 07/10/2021 - If you'd like to add png images to your builds, add fltkpngd.lib

11. Write down the sample code, build and run. You should get a pop up window:



Other errors you may encounter:
- "Fatal error LNK1104: cannot open file 'fltkd.lib'
I got this error when doing the above steps on my work pc.  Depending on your computer you may need to change step 9 to directly include the file path of the libraries. For example it would be FLTK->fltk 1.3.5->lib. (or you can just add the folder to the additional library dependencies in Linker).

EDIT 01/01/2021
I've now added a zip file to github containing a full program for this exercise:

4 comments:

  1. This was super helpful. Glad I found this blog. Thank you!

    ReplyDelete
  2. Replies
    1. I'm not quite sure what you mean? If you need a particular file, the git repro is here:
      https://github.com/fltk/fltk

      Delete