'How does one use FLTK library using Bjarne's GUI's header file in his book Programming principles and practices?

#include "Simple_window.h"
#include "Graph.h"

int main()
{
    using namespace Graph_lib;

    Point tl(100, 100);

    Simple_window win(tl, 600, 400, "Canvas");

    Polygon poly;

    poly.add(Point(300, 200));
    poly.add(Point(350, 100));
    poly.add(Point(400, 200));

    poly.set_color(Color::red);

    win.attach(poly);

    win.wait_for_button();
}

The above code has to create a GUI window with a shape rendered on its canvas but it does not run the way it should throwing errors like ambiguous windows specified, no Point type found even though all the libraries and header files are properly placed as specified in the book. I also tried commenting and uncommenting certain parts of the supporting GUI library from Bjarne's site as done by others and also reading some of the error messages but of no use. It keeps throwing ambiguous windows specified error!

Right now my only aim is to run the code above on my machine.



Solution 1:[1]

I can't tell you exactly how to compile the given code and I don't think your problem is related to FLTK or building (and optionally installing) FLTK. It is a well-known problem that Bjarne Stroustrup's files as posted by him are broken and need several fixes to be compileable. I can only give some links which may help you to fix your copies of the files.

  1. You may want to download the original files from Dr. B.'s GitHub repository (if you didn't): https://github.com/BjarneStroustrup/Programming-_Principles_and_Practice_Using_Cpp

  2. Someone posted a long guide on how to fix the files and (at the end of the original post) a zip file with his fixed files. There are several more comments with additional minor fixes. If you follow the thread you may be successful, but I don't know for sure: https://groups.google.com/g/ppp-public/c/BtlzdWGuQpQ/m/KuDN4u-SPKgJ

As a FLTK developer I see such questions frequently but since I don't have the book I can't really say how to compile the examples of the book.

I'd appreciate if you could confirm that the link(s) above helped so we can redirect further questions here.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Albrecht Schlosser