I'm using Programming: Practice and Principles Using C++ and I've hit a roadblock. Chapters 12-16 cover GUI programming and require the use of the Fast Light Toolkit. Here is what I've done so far. If you need more information I'd be happy to provide.

1. Using Dev-C++'s "Check for Updates and Packages," I downloaded and installed FLTK package.
2. Created new GUI FLTK project (this is now available since I installed package).
3. Added header files and cpp file to project (the cpp file calls header files which call headers from FLTK include folder)

Here's where it gets tricky.

At first I was getting compiler errors like Fl.h (things that are part of FLTK library) is unavailable. Then I went to project options - include directories - and included the folder from the FLTK folder that held those headers(wasn't sure why I had to do this since the project was an FLTK project). Now I'm getting linker errors of undefined references to objects such as


undefined reference to Simple_window::Simple_window(Point, int, int, string const)

I removed the directories I included, but I still get the linker errors instead of the compiler errors. I guess this is a step in the right direction...but I'm not sure where to go from here.

The header files that call on the FLTK headers can be found here.

http://www.stroustrup.com/Programming/Graphics/

Here is the cpp file code

#include "Simple_window.h"  // get access to our window library
#include "Graph.h"          // get access to our graphics library facilties

int main()
{
    using namespace Graph_lib; // our graphics facilities are in Graph_lib
   
    Point tl(100,100);         // to become top left corner of window
   
    Simple_window win(tl,600,400,"Canvas"); // make a simple window
   
    Polygon poly; // make a shape (a polygon)
   
    poly.add(Point(300,200));     // add point
    poly.add(Point(350,100));     // add another point
    poly.add(Point(400,200));     // add a third point
   
    poly.set_color(Color::red);   // adjust properties of poly
   
    win.attach(poly);             // connect poly to window
   
    win.wait_for_button();        // give control to display engine
}

Basically I have headers that include the FLTK headers, and for some reason this causes problems.

Put in all the cpp files into the Project and leave the header files in the current directory. and then compile

Put in all the cpp files into the Project and leave the header files in the current directory. and then compile

Okay I started a new FLTK project and put just the cpp file into it. Still same linker errors though. Here is what the directories look like.

Where most of my cpp and header files are stored:
C:\\Users\Alex\C++

Here is where the FLTK header files are stored:
C:\\Dev-Cpp\include\Fl

*there are also a lot of other FLTK files in other parts of Dev-Cpp folder.

The odd thing is that when I start a new FLTK project it has a sample file that creates a window just fine because it has the FLTK headers right there in the cpp file.

For some reason files and headers from my C++ folder are having problems accessing headers and files in the Dev-Cpp folder (I'm guessing, I really don't know.)

I never used FLTK So as a newbie I suggest this.
Well
Firstly As this is a guess, make a backup copy of all the source code.

Next,

Remove
FL/ from all the header includes in the code ..... For example in

File GRAPH.H and Graph.cpp
Change,

#include <FL/fl_draw.H>

to

#include <fl_draw.H>

Hopefully it should work out.

Well I was thinking about it and because of your post I realized that I needed the other cpp files from the site as well. I only downloaded the header files and not the cpp files because I thought the cpp files were for later exercises or something.

This has put me on the right track, I've got everything from the book page in the project except for the std_lib_facilities.h because I already have a std_lib_facilities.h that is longer than the one posted (can be found elsewhere on the site).

I tried to compile the file I posted and it got a long way in compiling, it got through the Graph, GUI, Simple_Window, but it failed when it tried to compile Window.cpp.

In Window.cpp it highlights the line
:Fl_Window(ww,hh,title.c_str()),w(ww),h(hh)
saying that the prototype doesn't match any in class Graph_lib::Window.

At first I thought this was an incompliance with the Fl_Window header because it denotes the 3rd argument as a char rather than a string, but the 3rd argument in the line above is turned into a c_str anyway so that can't be the problem.

I'm getting close...but I'm not sure how to comprehend that error message. If you need any more information I'd be happy to provide anything.

I noticed that the std_lib_facilities.h was different than what I thought it was, because he has 2 std_lib_facilities.h on the site.

So I changed it and compiled and I got to the very end and all I'm getting now is a

[Build Error] [ProjectName.exe] Error 1

To add to the above post, the error is in Makefile.win (which I got from Stroustrup's site and is part of the project)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.