FLTK issue compiling first program [SOLVED] linux / g++ 4.9.2 / fltk 1.3.0 / PPP2ndEd

4,029 views
Skip to first unread message

thejoh...@gmail.com

unread,
Apr 18, 2015, 6:15:32 AM4/18/15
to ppp-p...@googlegroups.com
Firstly big thanks to EdHenFab, Sebastien for helping me sort this issue in the previous thread. Between you and Google I've been able to make sense of what the compiler is telling me. I've learned a lot about programming in this process.

I've made a new thread to make this easier to find online.

These are the steps I needed to take to get the FLTK examples in Bjarne's 2nd edition of "Programming: Principles and Practices using C++" on Ubuntu linux / g++ 4.9.2 / fltk 1.3.0. Of course YMMV but this might help someone down the line. (Do Google the errors your receive, they're usually very understandable with the amount of knowledge we have this far in PPP.)

This assumes you have installed FLTK and test FLTK compiles and runs. (If not go to... http://www.fltk.org/doc-1.3/basics.html and use "g++ -Wall -std=c++11 RENAME_ME.cpp `fltk-config --ldflags --use-images` -o RENAME_ME" to compile the test from that page)

Okay here goes...

1. We are trying to get this to work: (1st example from Ch. 12)

#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();
}


2. Put all dependant files in the same folder.

Downloaded from http://www.stroustrup.com/Programming/PPP2code/
(I only used the uppercase GUI.h as this one is included in the other files.)

3. Use this script to compile and link:

g++ -w -Wall -std=c++11 Graph.cpp Window.cpp GUI.cpp Simple_window.cpp MY_CPP_FILE.cpp `fltk-config --ldflags --use-images` -o MY_EXECUTABLE

Please rename MY_CPP_FILE and MY_EXECUTABLE to whatever you've saved your example as.

4. Try to compile and check the first error:

g++ -w -Wall -std=c++11 Graph.cpp Window.cpp GUI.cpp Simple_window.cpp "13-drill-01-graphics-practise.cpp" `fltk-config --ldflags --use-images` -o "13-drill-01-graphics-practise" (in directory: /home/jf/Desktop/PPP/ch/13_recreate_build_steps)
In file included from Graph.cpp:1:0:
Graph.h:89:2: error: ‘vector’ does not name a type
  vector<T*> v;
  ^
...

5. Graph.h line 10: Uncomment #include "std_lib_facilities.h"

6. Try to compile and check the first error:

g++ -w -Wall -std=c++11 Graph.cpp Window.cpp GUI.cpp Simple_window.cpp "13-drill-01-graphics-practise.cpp" `fltk-config --ldflags --use-images` -o "13-drill-01-graphics-practise" (in directory: /home/jf/Desktop/PPP/ch/13_recreate_build_steps)
Graph.cpp: In member function ‘void Graph_lib::Polygon::add(Graph_lib::Point)’:
Graph.cpp:74:19: error: no matching function for call to ‘Graph_lib::Point::Point(int, int)
   Point ignore(0,0);
                   ^
Graph.cpp:74:19: note: candidates are:
In file included from Graph.h:5:0,
                 from Graph.cpp:1:
Point.h:9:8: note: Graph_lib::Point::Point()
 struct Point {
        ^
Point.h:9:8: note:   candidate expects 0 arguments, 2 provided
Point.h:9:8: note: constexpr Graph_lib::Point::Point(const Graph_lib::Point&)
Point.h:9:8: note:   candidate expects 1 argument, 2 provided
Point.h:9:8: note: constexpr Graph_lib::Point::Point(Graph_lib::Point&&)
Point.h:9:8: note:   candidate expects 1 argument, 2 provided
...

7. Point.h lines 11 & 12: Uncomment constructors

    Point(int xx, int yy) : x(xx), y(yy) { }
    Point() :x(0), y(0) { }


8. Try to compile and check the first error

g++ -w -Wall -std=c++11 Graph.cpp Window.cpp GUI.cpp Simple_window.cpp "13-drill-01-graphics-practise.cpp" `fltk-config --ldflags --use-images` -o "13-drill-01-graphics-practise" (in directory: /home/jf/Desktop/PPP/ch/13_recreate_build_steps)
GUI.cpp:55:1: error: redefinition of ‘Graph_lib::Menu::Menu(Graph_lib::Point, int, int, Graph_lib::Menu::Kind, const string&)’
 Menu::Menu(Point xy, int w, int h, Kind kk, const string& s)
 ^
In file included from GUI.cpp:1:0:
GUI.h:95:9: note: ‘Graph_lib::Menu::Menu(Graph_lib::Point, int, int, Graph_lib::Menu::Kind, const string&)’ previously defined here
         Menu(Point xy, int w, int h, Kind kk, const string& label)
         ^
...


There are quite a few of these redefinition errors. Changing the appropriate definitions in the .h files to declarations only (leaving the definition in the .cpp file) fixes this for me.

9. Gui.h line 95: change Menu definition to declaration: (comment out the definition part and add a semi-colon as underlined)

        Menu(Point xy, int w, int h, Kind kk, const string& label);
        /*    : Widget(xy,w,h,label,0), k(kk), offset(0)
        {}*/


10. Try compile and check first error

g++ -w -Wall -std=c++11 Graph.cpp Window.cpp GUI.cpp Simple_window.cpp "13-drill-01-graphics-practise.cpp" `fltk-config --ldflags --use-images` -o "13-drill-01-graphics-practise" (in directory: /home/jf/Desktop/PPP/ch/13_recreate_build_steps)
In file included from Simple_window.cpp:7:0:
Simple_window.h:9:24: error: reference to ‘Window’ is ambiguous
 struct Simple_window : Window {
                        ^
In file included from /usr/include/FL/Xutf8.h:33:0,
                 from /usr/include/FL/fl_utf8.h:73,
                 from /usr/include/FL/Fl.H:39,
                 from fltk.h:4,
                 from Window.h:4,
                 from GUI.h:10,
                 from Simple_window.h:2,
                 from Simple_window.cpp:7:
/usr/include/X11/X.h:96:13: note: candidates are: typedef XID Window
 typedef XID Window;
             ^
...


Window is clashing with X11's Window.

11. Simple_window.h line 9: Add fully qualified name for Window:

struct Simple_window : Graph_lib::Window {

12. Try compile and check first error

g++ -w -Wall -std=c++11 Graph.cpp Window.cpp GUI.cpp Simple_window.cpp "13-drill-01-graphics-practise.cpp" `fltk-config --ldflags --use-images` -o "13-drill-01-graphics-practise" (in directory: /home/jf/Desktop/PPP/ch/13_recreate_build_steps)
Simple_window.cpp:11:1: error: redefinition of ‘Simple_window::Simple_window(Graph_lib::Point, int, int, const string&)’
 Simple_window::Simple_window(Point xy, int w, int h, const string& title) :
 ^
In file included from Simple_window.cpp:7:0:
Simple_window.h:10:2: note: ‘Simple_window::Simple_window(Graph_lib::Point, int, int, const string&)’ previously defined here
  Simple_window(Point xy, int w, int h, const string& title )
  ^
...

13.
Simple_window.h line 10: change Simple_window constructor definition to declaration: (comment out the definition part and add a semi-colon)

    Simple_window(Point xy, int w, int h, const string& title );
    /*: Window(xy,w,h,title),
      button_pushed(false),
      next_button(Point(x_max()-70,0), 70, 20, "Next", cb_next) { attach(next_button); }
    */


14. Try compile, check first error.

g++ -w -Wall -std=c++11 Graph.cpp Window.cpp GUI.cpp Simple_window.cpp "13-drill-01-graphics-practise.cpp" `fltk-config --ldflags --use-images` -o "13-drill-01-graphics-practise" (in directory: /home/jf/Desktop/PPP/ch/13_recreate_build_steps)
Simple_window.cpp:21:6: error: prototype for ‘bool Simple_window::wait_for_button()’ does not match any in class ‘Simple_window’
 bool Simple_window::wait_for_button()
      ^
In file included from Simple_window.cpp:7:0:
Simple_window.h:15:7: error: candidate is: void Simple_window::wait_for_button()
  void wait_for_button()
       ^
Simple_window.cpp:42:6: error: redefinition of ‘static void Simple_window::cb_next(Graph_lib::Address, Graph_lib::Address)’
 void Simple_window::cb_next(Address, Address pw)
      ^
...

15. Simple_window.h line 15: Change 'void' to 'bool':  bool wait_for_button()

16. Try compile, check first error.

g++ -w -Wall -std=c++11 Graph.cpp Window.cpp GUI.cpp Simple_window.cpp "13-drill-01-graphics-practise.cpp" `fltk-config --ldflags --use-images` -o "13-drill-01-graphics-practise" (in directory: /home/jf/Desktop/PPP/ch/13_recreate_build_steps)
Simple_window.cpp:21:6: error: redefinition of ‘bool Simple_window::wait_for_button()’
 bool Simple_window::wait_for_button()
      ^
In file included from Simple_window.cpp:7:0:
Simple_window.h:15:7: note: ‘bool Simple_window::wait_for_button()’ previously defined here
  bool wait_for_button()
       ^

17.
Simple_window.h line 15: change wait_for_button() definition to declaration: (uncomment + semicolon as before)

    bool wait_for_button();
    // modified event loop
    // handle all events (as per default), but quit when button_pushed becomes true
    // this allows graphics without control inversion
    /*{
        while (!button_pushed) Fl::wait();
        button_pushed = false;
        Fl::redraw();
    }*/


18. Try compile, check first error.

g++ -w -Wall -std=c++11 Graph.cpp Window.cpp GUI.cpp Simple_window.cpp "13-drill-01-graphics-practise.cpp" `fltk-config --ldflags --use-images` -o "13-drill-01-graphics-practise" (in directory: /home/jf/Desktop/PPP/ch/13_recreate_build_steps)
Simple_window.cpp:42:6: error: redefinition of ‘static void Simple_window::cb_next(Graph_lib::Address, Graph_lib::Address)’
 void Simple_window::cb_next(Address, Address pw)
      ^
In file included from Simple_window.cpp:7:0:
Simple_window.h:29:14: note: ‘static void Simple_window::cb_next(Graph_lib::Address, Graph_lib::Address)’ previously defined here
  static void cb_next(Address, Address addr) // callback for next_button
              ^
...

19. Simple_window.h line 29: Change definition of cb_next to declaration only (as before)

    static void cb_next(Address, Address addr); // callback for next_button
    //    { reference_to<Simple_window>(addr).next(); }
    /*{
        static_cast<Simple_window*>(addr)->next();
    }*
/

20. Compile, check first error.

g++ -w -Wall -std=c++11 Graph.cpp Window.cpp GUI.cpp Simple_window.cpp "13-drill-01-graphics-practise.cpp" `fltk-config --ldflags --use-images` -o "13-drill-01-graphics-practise" (in directory: /home/jf/Desktop/PPP/ch/13_recreate_build_steps)
Simple_window.cpp:50:6: error: redefinition of ‘void Simple_window::next()’
 void Simple_window::next()
      ^
In file included from Simple_window.cpp:7:0:
Simple_window.h:35:7: note: ‘void Simple_window::next()’ previously defined here
  void next() { button_pushed = true; }
       ^
Compilation failed.


21. Simple_window.h line 39: Change definition to declaration

void next(); /*{ button_pushed = true; }*/


------------------------------------
----------------------------------------------------------


Now it should hopefully work!

Attached are the files as I've edited them all in one zip folder if you're having trouble maybe try those.

Thanks,
John.


13_recreate_build_steps.zip

EdHenFab

unread,
Apr 18, 2015, 6:23:46 PM4/18/15
to ppp-p...@googlegroups.com
Congratulations on persevering through this! I haven't installed fltk yet (am presently doing the exercises in chapter 6), but will be approaching it with a feeling of impending dread! lol.
You had to make quite a few changes to Mr. Stroustrup's fltk support files. Perhaps his files were created years ago for the first edition of PPP and since then flkk has updated
its files in such a way that breaks the synchronicity between Mr. Stroustrup's files and fltk's. Are you using the latest edition of fltk?


John Flynn

unread,
Apr 21, 2015, 12:27:24 PM4/21/15
to ppp-p...@googlegroups.com
Yes although it works I'm definitely not one to second guess Bjarne. I'm looking forward to having a greater knowledge then I would know if I should have changed things as I should, if I perhaps could have configured my compiler/system better or make alterations that could have impacted less on the given code.

Thanks again for your help!
John.



--
You received this message because you are subscribed to a topic in the Google Groups "PPP-public" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ppp-public/BtlzdWGuQpQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ppp-public+...@googlegroups.com.
To post to this group, send email to ppp-p...@googlegroups.com.
Visit this group at http://groups.google.com/group/ppp-public.
For more options, visit https://groups.google.com/d/optout.

Art Werschulz

unread,
Apr 21, 2015, 1:14:29 PM4/21/15
to ppp-p...@googlegroups.com
Hi.

On Apr 21, 2015, at 12:26 PM, John Flynn wrote:

> Yes although it works I'm definitely not one to second guess Bjarne. I'm looking forward to having a greater knowledge then I would know if I should have changed things as I should, if I perhaps could have configured my compiler/system better or make alterations that could have impacted less on the given code.

I don't know whether Bjarne monitors this group. But he welcomes suggestions. Once you're convinced that the revised FLTK support files work for all the sample code in the text, it wouldn't be a bad idea to send him the corrected versions of these files.

Art Werschulz (8-{)} "Metaphors be with you." -- bumper sticker
GCS/M (GAT): d? -p+ c++ l u+(-) e--- m* s n+ h f g+ w+ t++ r- y?
Internet: agw STRUDEL comcast.net



John Flynn

unread,
Apr 21, 2015, 2:02:08 PM4/21/15
to ppp-p...@googlegroups.com
Indeed Art thanks. Yes my plan was to work through the graphics chapters and understand everything a bit better before bugging him ;)

Message has been deleted

Gregory Toepperwein

unread,
Jul 4, 2015, 4:05:43 PM7/4/15
to ppp-p...@googlegroups.com
First, thank you for posting this, it is was a major help in getting Stroustrup's files working for me in a timely fashion.

Second, there is one additional error that was overlooked when you put this guide together.  It was in your messages from the error log the original thread, so clearly you fixed it too.  Thought is should be added to the thread for completeness:

Graph.h:159:25: warning: narrowing conversion of fl_color()’ from Fl_Color {aka unsigned int}’ to int inside { } [-Wnarrowing]
 
Color lcolor {fl_color()};

The solution being to edit line 29 of the same file to:
Color(unsigned int cc) :c(Fl_Color(cc)), v(visible) { }

thejoh...@gmail.com

unread,
Jul 5, 2015, 7:07:06 AM7/5/15
to ppp-p...@googlegroups.com
Thanks Gregory!

Art Werschulz

unread,
Jul 6, 2015, 8:57:19 AM7/6/15
to ppp-p...@googlegroups.com
Hi all.

I’m currently in the process of changing all the initializers in the GUI code from parentheses to braces, to keep the source code in sync with what’s in the book.

Line 122 of Graph.h is
Shape() : lcolor(fl_color()),
Compiling under Fedora Linux 21 with
g++ -I/usr/local/include/bjarne -O3 -std=c++11 -Wall -o GUI.o -c GUI.cpp
I get no errors. Changing it to
Shape() : lcolor{fl_color()},
as on page 496 of the text, I get
Graph.h:122:33: warning: narrowing conversion of 'fl_color()' from
'Fl_Color {aka unsigned int}' to 'int' inside { } [-Wnarrowing]
I can fix this by changing the line to
Shape() : lcolor{static_cast<Color>(fl_color())},

I don’t know why ()-initialization gives no warning, but {}-initialization gives the narrowing warning. I’ve written Bjarne, asking for some insight.

I’m also trying to get the GUI to work on Mac OS X. Note that although you can invoke the C++ compiler that you get with the Mac OS X Developer Tools as “g++”, this compiler is *not* “real” g++, i.e., the C++ compiler from GCC (the Gnu Compiler Collection). Here, I get a warning that “real” g++ doesn’t give me, namely
./Window.h:25:12: warning: 'Graph_lib::Window::resize' hides overloaded
virtualfunction [-Woverloaded-virtual]
void resize(int ww, int hh) { w=ww, h=hh; size(ww,hh); }
^
/usr/local/include/FL/Fl_Window.H:261:16: note: hidden overloaded virtual
function 'Fl_Window::resize' declared here: different number of parameters
(4 vs 2)
I don’t know why the Linux compiler gives no warning, but the Mac compiler does give a warning. At any rate, the GUI almost works. A window will appear on the screen, but it never contains anything. I’ll mull this one over.

Art Werschulz
a...@comcast.net



Ephraim Raj

unread,
May 3, 2016, 12:43:04 AM5/3/16
to PPP-public
I cannot thank you enough. There is no way I could have done this without you! Thanks a lot!

thejoh...@gmail.com

unread,
May 3, 2016, 9:54:45 AM5/3/16
to PPP-public
Great! I'm glad it helped :)

Anthony Gutierrez

unread,
Oct 3, 2016, 1:50:56 AM10/3/16
to PPP-public
This was a tremendous help. Spent the entire day trying to sort this out and finally got it work due in large part to this thread.

I had to make an additional change that I don't see listed, so I'm including it in case someone else runs in to the same problem.
Setup: Microsoft Visual Studio Community 2015, Visual C++ 2015, FLTK 1.3.3.

Error    C2440    'return': cannot convert from 'std::ifstream' to 'bool'    Ch12Drill    graph.cpp    line 313

    bool can_open(const string& s)
      // check if a file named s exists and can be opened for reading
    {
      ifstream ff(s.c_str());
      // return ff;  /* error here, replaced with below */
      return (ff) ? true : false;  // converts ff object to true/false bool
    }

Love the book and appreciate the community around it.

thejoh...@gmail.com

unread,
Oct 5, 2016, 11:02:54 AM10/5/16
to PPP-public
Great Anthony good to see this is still of use to people.

Good to add the point about the MSVS issue I'm sure that will help others.

Happy PPPing :)

John.

rmarqu

unread,
May 7, 2017, 1:58:01 PM5/7/17
to PPP-public
Hi all. Just started on C++ programming and finally got to GUI part of PPP2. Thanks for figuring this out for us.  It worked for me using openSuse dist. 

John Flynn

unread,
May 8, 2017, 2:07:36 PM5/8/17
to ppp-p...@googlegroups.com
Great glad to hear this is still working.

On 7 May 2017 at 18:58, rmarqu <raymarq...@gmail.com> wrote:
Hi all. Just started on C++ programming and finally got to GUI part of PPP2. Thanks for figuring this out for us.  It worked for me using openSuse dist. 

--
You received this message because you are subscribed to a topic in the Google Groups "PPP-public" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ppp-public/BtlzdWGuQpQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ppp-public+unsubscribe@googlegroups.com.

To post to this group, send email to ppp-p...@googlegroups.com.

Christiano

unread,
May 8, 2017, 2:38:40 PM5/8/17
to PPP-public
Good job!!!

I followed your guide by adding the Gregory step, and additionally I had to add the following changes:

=== fltk.h ====

change from

#include "Fl/Fl_JPEG_Image.H"
#include "Fl/Fl_GIF_Image.H"

to

#include "FL/Fl_JPEG_Image.H" #include "FL/Fl_GIF_Image.H"

====Graph.cpp line 313 ======== [1]

from
return ff;

to
return static_cast<bool>(ff);

==========

My system is Freebsd using Clang(LLVM) compiler
And FLTK 1.3.3

The command line used:
CC -I/usr/local/include -L/usr/local/lib `fltk-config --ldflags --use-images` -std=c++11 *.cpp

I've attached the final version which use:
1- Thejoh modification
2- Gregory modification
3- My modification

[1] Edit before sending: I have now seen that Anthony has also created another solution to the "return ff" problem.

---------------------------------------------
Werschulz,

using FreeBSD+Clang with -Wall option gives also:
[...]
 ./Window.h:25:7: warning: 'Graph_lib::Window::resize' hides overloaded virtual function [-Woverloaded-virtual]

void resize(int ww, int hh) { w=ww, h=hh; size(ww,hh); }
^
/usr/local/include/FL/Fl_Window.H:261:16: note: hidden overloaded virtual function 'Fl_Window::resize' declared
here: different number of parameters (4 vs 2)
  virtual void resize(int X,int Y,int W,int H);
^
[...]

But my window is being drawn correctly:
[image]

[/image]

  And according with:
https://clang.llvm.org/get_started.html

"From Xcode 4.2, Clang is the default compiler for Mac OS X."

my clang is 3.8.0
my fltk is 1.3.3

gui2.tar.gz
Message has been deleted

Zech zhao

unread,
Aug 5, 2019, 2:55:27 PM8/5/19
to PPP-public
With all the modification to the original code, my mac was finally succeed to compile.

However, when the compiled file is executaded, the canvas shows with nothing on it.

Anyone else has also encontered this problem?

Thanks

Keeyan Kazemi

unread,
Mar 16, 2020, 3:59:23 PM3/16/20
to PPP-public
I had another bug, running on MacOS Catalina. When I try linking everything, I get the following linker error:

duplicate symbol 'get_rand()' in:

    Graph.o

    Simple_window.o

duplicate symbol 'seed_randint(int)' in:

    Graph.o

    Simple_window.o

duplicate symbol 'get_rand()' in:

    Graph.o

    Window.o

duplicate symbol 'seed_randint(int)' in:

    Graph.o

    Window.o

duplicate symbol 'get_rand()' in:

    Graph.o

    GUI.o

duplicate symbol 'seed_randint(int)' in:

    Graph.o

    GUI.o

duplicate symbol 'get_rand()' in:

    Graph.o

    fltk_test.o

duplicate symbol 'seed_randint(int)' in:

    Graph.o

    fltk_test.o


I fixed it by commenting out the get_rand() and seed_randint() functions in std_lib_facilities.

Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Imtiaz Ahmed

unread,
May 1, 2020, 1:50:51 PM5/1/20
to PPP-public
This was a huge help - even in April 2020! It was very satisfying to go through each step and see errors and warnings disappear!

I'm using Manjaro 20 KDE and have been able to compile everything perfectly. There were couple of things that was an issue, but I was able to go through them as well. Here are the issues I faced and how I fixed them in case it helps someone in the future:

1. Return error for ifstream:

Here's the error I've been seeing:

Graph.cpp: In function bool Graph_lib::can_open(const string&)’:
Graph.cpp:313:9: error: cannot convert std::ifstream {aka std::basic_ifstream<char>’} to bool in return
 
313 |  return ff;

The way to fix is in the Graph.cpp file, line 313, change from

return ff;

to:
return static_cast <bool> (ff);

2. Instruction #9 in the original thread mentions Gui.h line 95

The name should be "GUI.h" ; line 95.

3. Multiple definition for get_rand() and seed_randint(int):

I was getting the following linker error, and as a result, the code wasn't compiling:

/usr/bin/ld: /tmp/ccQx8RDh.o: in function `get_rand()':
Window.cpp:(.text+0x0): multiple definition of `
get_rand()';
/tmp/ccYLFDUi.o:Graph.cpp:(.text+0x0): first defined here
/usr/bin/ld: /tmp/ccQx8RDh.o: in function `seed_randint(int)'
:
Window.cpp:(.text+0x77): multiple definition of `seed_randint(int)';
/tmp/ccYLFDUi.o:Graph.cpp:(.text+0x77): first defined here
/usr/bin/ld: /tmp/ccWUjcih.o: in function `
get_rand()':
GUI.cpp:(.text+0x0): multiple definition of `get_rand()'
;
 
/tmp/ccYLFDUi.o:Graph.cpp:(.text+0x0): first defined here
/usr/bin/ld: /tmp/ccWUjcih.o: in function `seed_randint(int)'
:GUI.cpp:(.text+0x77): multiple definition of `
seed_randint(int)';
/tmp/ccYLFDUi.o:Graph.cpp:(.text+0x77): first defined here

The way I fixed it is I commented the entire get_rand() and seed_randint(int) area of the std_lib_facilities.h file (line 218 to 228):

/*
default_random_engine& get_rand()
{
    static default_random_engine ran;
    return ran;
};
 
// void seed_randint(int s) { get_rand().seed(s); }
 
inline int randint(int min, int max) {  return uniform_int_distribution<>{min, max}(get_rand()); }
 
inline int randint(int max) { return randint(0, max); }
*/



This solved all issues and the file compiled and ran properly. Again thanks to everyone who helped!

Reggie Veggie-8

unread,
May 14, 2020, 2:37:38 AM5/14/20
to PPP-public
Thanks All. This really helped me work through debugging. 

Additionally, There were a few linking issues I ran into on XCode/Clang Compiler that maybe I can help with. 

Issue: Linking the source code to the FLTK libraries. 
Solve: In the frameworks/libraries build setting under the general tab of the target, I added the both the fltk dynamic library and the fltk image library. Also I added the headers in the user search paths instead. This solved all of my linking issues. 

Hope this helps! 

alex garikana

unread,
May 22, 2020, 4:03:14 AM5/22/20
to PPP-public
These steps work still in 2020 for fltk 1.3.5.
Machine:- MackBook Pro.
Operating System:- OSX 10.12.16

1) I downloaded the fltk 1.3.5 source & buillt it. Pls check your C++ compiler options when building fltk. You can supply c++ compiler option to cmake build system(thats what is used) using the below env variables.
CXX=<your c++ compiler path>
CXXFLAGS=<c++ compiler flags if any>

For example:- CXXFLAGS="-std=c++11" & CXX=g++-9

fltk will be built & installed. Usually header files will go into /usr/local/include/FL & libraries will go into /usr/local/lib/

2) Appendix D in PPP gives a boilerplate program to check if your fltk lib has been successfully installed. Note for mac OSX users:- include '-framework Cocoa' at the end of your compilation command line to link fltk libraries with the cocoa framework. This is the windowing system used by fltk libraries on macosx.
3) Next step is to get the wrapper files given by Mr.Stroustrup to compile and link to fltk

One problem you will face here is with the 'std_lib_facilities.h" header we have been using until now. You will be better off to not use this from this point(chapter 12)
This involves a cleanup of the following files 'Window.h' which includes this. Remove the line #include "std_lib_facilities.h" from this header & try to compile 'Window.cpp' given by Mr.Stroustrup. It will throw errors for the missing declarations. Include these manually.

4) Once this is done, there are some cosmetic issues like missing namespaces etc that are highlighted in this post which should solve the problems.
5) Note that to compile your program successfully we need to include 'GUI.cpp' also as this contains the definition for some functions like Graph_lib::Button::attach(). This is a mess because Graph_lib::Button is partially defined in 'GUI.h' & 'GUI.cpp'

6) final command line should be like this g++ -std=c++11 Window.cpp Graph.cpp GUI.cpp <your file containing main>.cpp -lfltk -lfltk_forms -lfltk_gl -lfltk_images -lfltk_jpeg -lfltk_png -framework Cocoa


fl(non

DalMasso82

unread,
Dec 13, 2022, 1:45:30 PM12/13/22
to PPP-public
This solution also works in 2022.
FLTK 1.3.4
Thanks a lot.
Reply all
Reply to author
Forward
0 new messages