To anyone in the same predicament, I leave here what I did to finally be able to compile and get the window of the first program with FLTK on section 12.3 of Stroustrup's book "Programming: Principles and Practice using C++, 2nd Edition".
After installing FLTK on Kubuntu 14.04 with
$ sudo apt install libfltk1.3-dev
I could compile the example program on Appendix D with the use of
$ fltk-config --compile fltkTest.cpp
Thanks to this post, I could see how I could finally get it on track with the first example of chapter 12. Comparing the command of cwivagg and Nathan with the command generated with fltk-config, I ended with this command
$ clang++ -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/freetype2 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -g -O2 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT -Wl,-Bsymbolic-functions -lfltk_images -lfltk -lX11 -std=c++11 -o 's12_3_first' 's12_3_first.cpp' Simple_window.cpp Graph.cpp GUI.cpp Window.cpp
I had to add -lfltk_images and -std=c++11
However, now I had to deal with the errors that the compiler gave me. To get a working program, I had to do several changes to the sources that Stroustrup gave on http://www.stroustrup.com/Programming/PPP2code/
- I uncommented std_lib_facilities.h on Graph.h
- To resolve the ambiguity of Window, I needed to specify Graph_lib::Window on line 9 of Simple_window.h
- std_lib_facilities.h on lines 107 and 113 uses a i<0 comparison when i is
unsigned (but these are just warnings).
- Graph.h line 159 uses fl_color() but the compiler says it should be Fl_Color
- I needed to uncomment the constructors for Point in Point.h
- There are several redefinitions on Simple_window.cpp of Simple_window.h
On Simple_window.cpp I commented out the definitions for the constructor,
cb_next and wait_for_button (which is not the same as the one on
Simple_window.h). On Simple_window.h I commented out the definitions of
wait_for_button and next. By the way, wait_for_button does not work in
either form.
- In GUI.cpp there is another redefinition for the constructor of Menu. I
commented it out.
- I changed the last line of the example of section 12.3
from
win.wait_for_button;
to
Fl::run();
which I took from the example on Appendix D, because otherwise the window does
not close with its close button.
With all these changes I finally have the window as it should be, and the window close either with the Next button or the close button of the said window (with wait_for_button I needed to end the program from Konsole with Ctrl-c after I tried to close it with the close button of the window).
I hope the next person do not have to spend all the time I had to.
Edit: Well, checking at my system and the compiling command, I realized that there are several carpets repeated... and that they actually don't exist in my Kubuntu system. So, I have to write down in my answer what I finally do to get the window working:
To get an object file:
$ clang++ -O2 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT -g -std=c++11 -c Simple_window.cpp
To get the first program that we wanted
% clang++ -O2 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT -Wl,-Bsymbolic-functions -lfltk_images -lfltk -lX11 -g -std=c++11 Simple_window.o Graph.o GUI.o Window.o -o z3 s12_3_first.cpp
These are a hell lot easier (I almost can write them every time I need them)
Simple_window::Simple_window(Point, int, int, String const&)
Did you define that anywhere? – ArtificialitySimple_window
's constructor, and you have virtual functions inGraph_lib::Window
but no virtual destructor defined. Perhaps you just failed to link all the right.o
files together. These things have nothing to do with graphics in particular. – Fascism