libraries in Bjarne Stroustrup's book wont work

This is a discussion on libraries in Bjarne Stroustrup's book wont work within the C++ Programming forums, part of the General Programming Boards category; Im reading Bjarne Stroustrup's book "Programming Principals and Practices Using C++" and I cant get the graphics libraries he provides ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    44

    libraries in Bjarne Stroustrup's book wont work

    Im reading Bjarne Stroustrup's book "Programming Principals and Practices Using C++" and I cant get the graphics libraries he provides to compile. These libraries are a wrapper that interfaces with the FLTK widgets toolkit. I have FLTK set up and it compiles fine in my IDE. Here is the download page for Bjarne's source files:
    http://www.stroustrup.com/Programming/Graphics/

    if I could trouble someone to install FLTK and then download these files and run make on them I would really appreciate it. Just remember this is not my code, you are fixing Bjarne Stroustrup's code. I will update my Amazon review of this book with anything I learn about how to set up these libraries properly.

    one minor note, the std_lib_facilities.h file has to be one directory above the rest of the files

    here is the error message I get when I run make
    Code:
    In file included from Graph.cpp:8:
    Graph.h:140: error: ISO C++ forbids declaration of ‘Vector’ with no type
    Graph.h:140: error: expected ‘,’ or ‘...’ before ‘&’ token
    Graph.h:141: error: ISO C++ forbids declaration of ‘Vector’ with no type
    Graph.h:141: error: expected ‘,’ or ‘...’ before ‘&’ token
    Graph.cpp:235: error: redefinition of ‘Graph_lib::Circle::Circle(Point, int)’
    Graph.h:285: error: ‘Graph_lib::Circle::Circle(Point, int)’ previously defined here
    Graph.cpp:243: error: redefinition of ‘Point Graph_lib::Circle::center() const’
    Graph.h:290: error: ‘Point Graph_lib::Circle::center() const’ previously defined here
    Graph.cpp: In function ‘Graph_lib::Suffix::Encoding Graph_lib::get_encoding(const String&)’:
    Graph.cpp:410: error: ‘strlen’ was not declared in this scope
    # cc1plus 0.30 0.04
    make: *** [Graph.o] Error 1
    Last edited by shintaro; 07-30-2011 at 01:17 PM.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,202
    The error messages are fairly self-explanatory. No need to install FLTK to find the problems. You need to do minor fixes of the offending source code (or header file).

    Graph.h does not declare any type named Vector, but declares a (private) constructor and assignment operator that accept a Vector by const reference. Change the word "Vector" to Vector_ref in a couple of places to eliminate the first 4 error messages.

    The next two error messages are because there is a multiple definition (implementation) of a constructor for Graph_lib::Circle. The header file Graph.h provides a definition, and the source file Graph.cpp provides a definition. Remove one of them. Similarly for the member function Graph_lib::Circle::center().

    The last two error messages are because the function Grap_lib::get_encoding() makes use of the standard (C) function strlen() but the header for it is not #include'd anywhere. You have two choices to address this one.

    1) Add a line "#include <string.h>" to the top of Graph.cpp (this is the deprecated "C-way").

    2) Add a line "#include <cstring> to the top of Graph.cpp and change the call of strlen() to std::strlen().

    You might find similar problems in other code in this library as well. After all, make will typically stop after encountering the first source file with errors.

    It might pay to do a hunt for an Errata sheet (or section) for the book, as these errors might already be listed there (complaining in a review about problems in a book that are already listed as Errata - or that are fixed in a later edition of the book, if any - will make you look fairly silly unless you refer to the Errata list). It would probably be more helpful if you submitted a report to the publisher or to Stroustrup about errors with the online version of the code (as such things are provided gratis, usually) or for inclusion as Errata (which becomes a published list of known flaws in the edition, and possibly contributes to fixing the flaws in future editions).
    Right 98% of the time, and don't care about the other 3%.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    44
    grumpy- thx for your help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 09-05-2005, 06:26 AM
  2. calculator program from Bjarne Stroustrup's book
    By deduct in forum C++ Programming
    Replies: 4
    Last Post: 03-21-2003, 12:43 AM
  3. Bjarne Stroustrup The c++ Programming Language (3rd ed)
    By smirnoff in forum C++ Programming
    Replies: 3
    Last Post: 11-24-2002, 03:52 PM
  4. Bjarne Stroustrup
    By mithrandir in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 08-11-2001, 06:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21