0
#include <FL/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Window.H>

int main()
{
    using namespace fltk;
    FI_Window window(200, 200, "Window title");
    FI_Box box(0, 0, 200, 200, "Hey, I mean, Hello, World! ");
    window.show();
    return Fl:: run();
}

Above is basic FLTK program from the book Programming principles and Practices using C++ but the line using namespace fltk; is not working giving error message name must be a namespace name. I googled and found the above code line is correct but still it shows error. Can somebody please explain it and what to do?

I am using Visual Studio 2019 and C++ 17.

JaMiT
  • 14,422
  • 4
  • 15
  • 31
  • Where did you get that code from? Which par the of the book? – Galik Aug 06 '21 at 12:47
  • What version of FLTK does your book require for this program? What version do you have installed? (I'm guessing FLTK-2 and a FLTK-1.3 version, respectively, but might as well make sure.) – JaMiT Aug 06 '21 at 12:53
  • @Galik From Bjarne Stroustrup's Sir book Programming principles and practices using C++ from the appendix part "How to install FLTK". – Kshitij Kumar Aug 06 '21 at 12:54
  • @JaMiT Yes FLTK 1.3.6 – Kshitij Kumar Aug 06 '21 at 13:08
  • The example for fltk 1.3.7 does not have this namespace: [https://www.fltk.org/doc-1.3/basics.html](https://www.fltk.org/doc-1.3/basics.html) I see that the unreleased fltk 2.0 has a fltk namespace however. – drescherjm Aug 06 '21 at 13:40
  • @drescherjm Yes I also rechecked and found no namespace required. It seems like the problem is Visual Studio can't find the header files(.h) in include directries. Anyways Thanks for the correction! – Kshitij Kumar Aug 06 '21 at 14:43
  • You need to tell your compiler where to look by setting the "Additional Include Directories" setting for each configuration. You also will have to add the library to your linker settings for each configuration. This will be the same procedure for most third party libraries that you install by downloading binaries. If you use nuget, vcpkg and / or CMake the application configuration can be different in that these tools may setup the Visual Studio settings for you depending on how you are using them. – drescherjm Aug 06 '21 at 15:06
  • @drescherjm I have all those configured as told in the book. Now I am having problem with Fl_Windows is undefined and Fl_Box is undefined and all...How do I resolve these? – Kshitij Kumar Aug 06 '21 at 15:17
  • 1
    You most likely need to ask a brand new question. The original problem is solved. In your new question you will have to show the exact text (no pictures) of your error messages and the steps you made otherwise the question will be closed as a duplicate of the link that @JaMiT posted in the comments to his answer. You can get the text from the Output tab of Visual Studio. – drescherjm Aug 06 '21 at 15:37
  • @drescherjm Oo...Okay! – Kshitij Kumar Aug 07 '21 at 04:08

1 Answers1

1

The line

using namespace fltk;

is valid only with the experimental/alpha, and dormant/discontinued, 2.0 version of FLTK. It is odd that you were told to add this line, since the rest of your code uses the naming scheme from the current, stable 1.3 version.

Remove this line from your code.

JaMiT
  • 14,422
  • 4
  • 15
  • 31
  • Thanks for the help! @JaMit but now I have problems in the lines of codes following the namespace line. FI_Window undefined FI_Box undefined. What to do about these? – Kshitij Kumar Aug 06 '21 at 14:14
  • [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – JaMiT Aug 06 '21 at 15:21