Subscribe to 10 GOTO 10        RSS Feed
-----

FLTK 1.3.0 in VS2010: Setup

Icon 2 Comments
These instructions are for setting up FLTK v1.3.0 in VS2010.

I am using VS2010 Express SP1.

Warning: FLTK's interaction with VS seems to change pretty quickly between versions so if you are using a different version of FLTK I would imagine that the instructions will be slightly different.


Step 1: Download FLTK v1.3.0. I downloaded fltk-1.3.0-source.tar.gz -- this file type can be opened with 7Zip if you don't have something that will open it already on hand.

Step 2: Extract the files to some easy to locate directory. I did this by opening the .gz file in 7Zip, then double clicking on the .tar and then dragging the fltk-1.3.0 folder to my C:\CProjects folder where I tend to keep all C/C++ related work.

Step 3: Find the <install dir>\fltk-1.3.0\ide\VisualC2010 and double click on fltk.sln -- this *should* launch VS2010.

Step 4: Build Solution (F7) -- this will take a while. A long while. You will see some console windows pop up here and there (and if your are writing in a blog this might mess you up a bit).

After a few minuets in the output window you should see:

========== Build: 79 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

Which indicates that all 79 projects were built free of errors!

Side Track 1: Goto the <install dir>\fltk-1.3.0\test\ directory
-- you should see a large set of exe's and one of them should be demod.exe (possible demo.exe if you did not build in debugging mode). -- run the exe and play around with some of the demo programs. The source for each demo program is listed in the test directory as well.

Step 5
: Open a new instance of Visual C++ 2010, File > New > Project
Choose a name and location for your first FLTK project. For me I did:
Name: HelloFLTK
Location: C:\CProjects\Blog
Solution Name: HelloFLTK

Win32 Console Application
checked: Create directory for solution

Next > Next >

On Application Settings page
select Console application
Uncheck: Precompiled header
Check: Empty project (in that order)

<finish>

Step 6: From the main menu goto Project > Add New Item (ctrl+shift+A)

Select C++ File and give it a name at the bottom: hello.cpp

paste in this code (taken from <install director>\fltk-1.3.0\test\hello.cxx since we know it compiles fine since it already had).

// Taken from fltk's hello.cxx so that we know it is good code since it has already been built.
#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(340, 180);
    Fl_Box *box = new Fl_Box(20, 40, 300, 100, "Hello, FLTK!");
    box->box(FL_UP_BOX);
    box->labelfont(FL_BOLD + FL_ITALIC);
    box->labelsize(36);
    box->labeltype(FL_SHADOW_LABEL);
    window->end();
    window->show(argc, argv);
    return Fl::run();
}


now you will notice a lot of red underlines! So now we need to tell VS where to find FLTK.

save the file.

Step 7: From the main menu goto Project > Properties to bring up the project properties page.

Expand "Configuration Properties"

Step 7.1: Under C/C++ (click on C/C++ not "General") --
Click on the space next to "Additional Include Directories" press the down button and select <edit...>
Click in the "new line" button at the top right (looks like a folder with a star-burst in the corner), THEN click on the ellipses (...). Navigate to your "install dir" (for me C:\CProjects ) and select the fltk-1.3.0 directory.

This creates and entry like: C:\CProjects\fltk-1.3.0

press OK

Step 7.2
: Click on "Linker" in the left hand panel's list
Under "Addition Library Directories" we will do as before to add a directory:


This time we want to add the folder: <install dir>\fltk-1.3.0\lib
so for me that was: C:\CProjects\fltk-1.3.0\lib

Step 7.3: Under "Linker" in the right select "Input"
Under "Additional Dependencies" click on the list to the right, drop down, click <edit...>
add:

fltkd.lib
comctl32.lib


Press OK.

Step 8: Press F5 (or hit the little green arrow next to the word "debug" at the top).
You may have to answer "Yes" to "Would you like to build it"
A console window, AND a window saying "Hello, FLTK!"

click the X in the top right of the "Hello, FLTK!" window will end the program.

Step 9: To test farther take copy some of the code in one of the .cxx files under the test directory and see if you can compile other demos. Note I *belive* that some of them may require additional libraries be added to the "Linker > Input" list.

Now that you know how to look at a project's properties you can explore the fltk solution with all of the demo code and see what was need to build the original file.

Good luck programming!

Note: If you would like to avoid having to do quite so much work configuring each project there are two options:
#1 Built a template. If you are not on the express version of VS you should be able to setup a basic project like I did above and then export the project as a new template. Since I only have the express version I can't do this.

#2 Copy the <install dir>\fltk-1.3.0\FL directory to VS's include directory and likewise copy the lib directory over. -- note you will still have to add the libs to the "Linker > Inputs" But see 2.1

#2.1 if you REALLY don't like messing with the configuration then after #2 you can use:
#pragma comment(lib,"fltkd.lib")
#pragma comment(lib,"comctl32.lib")

at the top of your .cpp files that require those libraries (if the file does not require anything for FL then you don't need to add the #pragma lines but they will not hurt anything).

Note: When I was first trying to setup FLTK I kept getting linker errors. The problem was that every bit of documentation seemed to say I needed to compile with either /MT (release) or /MTd. Turns out that NEITHER of these should be selected for the procedure described above.

2 Comments On This Entry

Page 1 of 1

NickDMax Icon

22 June 2011 - 09:35 PM
Before I get a barrage of comments on my improper use of VS2010 -- I am not an IDE guy, I generally compile from my text editor so there are probably details that I am not aware of in VS.

For example I *think* that if you want to build a release version you have to do everything above over, starting with building FLTK in release mode (you don't have to delete the old libs etc. as the fltk build adds a "d" char to the end of file names built in debug). -- Alas that is troubles for another day.
0

laserbeak43 Icon

23 June 2011 - 04:05 PM
thanks for this, i got ungodly errors the last time i tried to get fltk working.
0
Page 1 of 1

September 2014

S M T W T F S
 123456
78910111213
1415 16 17181920
21222324252627
282930    

Recent Entries

Search My Blog

2 user(s) viewing

2 Guests
0 member(s)
0 anonymous member(s)