1

I've been trying to get the C++ graphics to work as I have an assignment involving this. I'm pretty sure my code is error free, but I am having trouble with compiling errors. I took this snippet from the book and it still doesn't work.

Header files I have included: http://www.stroustrup.com/Programming/Graphics/

I have also download FLTK-1.1.9 which I copied the FL folder into my project directory since I had some issues with files requesting them. I did not install FLTK-1.1.9 as I was told I wouldn't have to.

I'm using CLion, but I have tried compiling with clang(Apple LLVM version 8.1.0 (clang-802.0.42)) as well.

#include "Simple_window.h"    
#include "Graph.h"            // get access to our graphics library facilities

int main()
{
    using namespace Graph_lib;   // our graphics facilities are in Graph_lib

    Graph_lib::Point tl(100,100);           // to become top left  corner of window

    Simple_window win(tl,600,400,"Canvas");    // make a simple window

    Graph_lib::Polygon poly;                // make a shape (a polygon)

    poly.add(Point(300,200));    // add a point
    poly.add(Point(350,100));    // add another point
    poly.add(Point(400,200));    // add a third point 

    poly.set_color(Color::red);  // adjust properties of poly

    win.attach (poly);           // connect poly to the window

    win.wait_for_button();       // give control to the display engine
}




/Applications/CLion.app/Contents/bin/cmake/bin/cmake --build /Users/aaaaa/CLionProjects/Assignmen4/cmake-build-debug --target Assignmen4 -- -j 4
[ 50%] Linking CXX executable Assignmen4
Undefined symbols for architecture x86_64:
  "Fl::wait()", referenced from:
      Simple_window::wait_for_button() in main.cpp.o
  "Fl::redraw()", referenced from:
      Simple_window::wait_for_button() in main.cpp.o
  "Fl_Widget::hide()", referenced from:
      Graph_lib::Widget::hide() in main.cpp.o
  "Fl_Widget::show()", referenced from:
      Graph_lib::Widget::show() in main.cpp.o
  "Fl_Window::hide()", referenced from:
      vtable for Simple_window in main.cpp.o
  "Fl_Window::show()", referenced from:
      vtable for Simple_window in main.cpp.o
  "Fl_Window::flush()", referenced from:
      vtable for Simple_window in main.cpp.o
  "Fl_Window::handle(int)", referenced from:
      vtable for Simple_window in main.cpp.o
  "Fl_Window::resize(int, int, int, int)", referenced from:
      vtable for Simple_window in main.cpp.o
  "Fl_Window::~Fl_Window()", referenced from:
      Graph_lib::Window::~Window() in main.cpp.o
  "Graph_lib::Window::draw()", referenced from:
      vtable for Simple_window in main.cpp.o
  "Graph_lib::Window::attach(Graph_lib::Shape&)", referenced from:
      _main in main.cpp.o
  "Graph_lib::Window::attach(Graph_lib::Widget&)", referenced from:
      Simple_window::Simple_window(Graph_lib::Point, int, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in main.cpp.o
  "Graph_lib::Window::Window(Graph_lib::Point, int, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      Simple_window::Simple_window(Graph_lib::Point, int, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in main.cpp.o
  "Graph_lib::Polygon::add(Graph_lib::Point)", referenced from:
      _main in main.cpp.o
  "typeinfo for Graph_lib::Window", referenced from:
      typeinfo for Simple_window in main.cpp.o
  "vtable for Graph_lib::Open_polyline", referenced from:
      Graph_lib::Open_polyline::Open_polyline() in main.cpp.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "vtable for Graph_lib::Closed_polyline", referenced from:
      Graph_lib::Closed_polyline::Closed_polyline() in main.cpp.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "vtable for Graph_lib::Shape", referenced from:
      Graph_lib::Shape::Shape() in main.cpp.o
      Graph_lib::Shape::~Shape() in main.cpp.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "vtable for Graph_lib::Button", referenced from:
      Graph_lib::Button::Button(Graph_lib::Point, int, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, void (*)(void*, void*)) in main.cpp.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "vtable for Graph_lib::Window", referenced from:
      Graph_lib::Window::~Window() in main.cpp.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "vtable for Graph_lib::Polygon", referenced from:
      Graph_lib::Polygon::Polygon() in main.cpp.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "_fl_color_", referenced from:
      fl_color() in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [Assignmen4] Error 1
make[2]: *** [CMakeFiles/Assignmen4.dir/all] Error 2
make[1]: *** [CMakeFiles/Assignmen4.dir/rule] Error 2
make: *** [Assignmen4] Error 2

when trying to use cmake to compile the directory, this is the errors that i receive. i have just updated XCODE to the most recent version.

Compiling Fl.cxx...
In file included from Fl.cxx:35:
In file included from ../FL/x.H:41:
../FL/mac.H:49:17: error: use of undeclared identifier 'NewRgn'
  Fl_Region R = NewRgn();
                ^
../FL/mac.H:50:3: error: use of undeclared identifier 'SetRectRgn'
  SetRectRgn(R, x, y, x+w, y+h);
  ^
../FL/mac.H:54:3: error: use of undeclared identifier 'DisposeRgn'; did you mean
      'DisposePtr'?
  DisposeRgn(r);
  ^~~~~~~~~~
  DisposePtr
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Headers/MacMemory.h:1188:1: note: 
      'DisposePtr' declared here
DisposePtr(Ptr p)                                             __OSX_AVAI...
^
In file included from Fl.cxx:35:
In file included from ../FL/x.H:41:
../FL/mac.H:54:14: error: cannot initialize a parameter of type 'Ptr'
      (aka 'char *') with an lvalue of type 'Fl_Region'
      (aka 'OpaqueRgnHandle *')
  DisposeRgn(r);
             ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Headers/MacMemory.h:1188:16: note: 
      passing argument to parameter 'p' here
DisposePtr(Ptr p)                                             __OSX_AVAI...
               ^
In file included from Fl.cxx:35:
In file included from ../FL/x.H:41:
../FL/mac.H:72:3: error: unknown type name 'CursHandle'; did you mean
      'CharsHandle'?
  CursHandle cursor;
  ^~~~~~~~~~
  CharsHandle
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/Carbon.framework/Frameworks/HIToolbox.framework/Headers/TextEdit.h:352:41: note: 
      'CharsHandle' declared here
typedef CharsPtr *                      CharsHandle;
                                        ^
In file included from Fl.cxx:35:
In file included from ../FL/x.H:41:
../FL/mac.H:99:8: error: unknown type name 'CursHandle'; did you mean
      'CharsHandle'?
extern CursHandle fl_default_cursor;
       ^~~~~~~~~~
       CharsHandle
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/Carbon.framework/Frameworks/HIToolbox.framework/Headers/TextEdit.h:352:41: note: 
      'CharsHandle' declared here
typedef CharsPtr *                      CharsHandle;
                                        ^
Fl.cxx:487:3: error: use of undeclared identifier 'GetPort'
  GetPort( &port );
  ^
Fl.cxx:489:5: error: use of undeclared identifier 'QDFlushPortBuffer'
    QDFlushPortBuffer( port, 0 );
    ^
Fl.cxx:715:27: warning: '&&' within '||' [-Wlogical-op-parentheses]
    if (grab() || modal() && window != modal()) return 0;
               ~~ ~~~~~~~~^~~~~~~~~~~~~~~~~~~~
Fl.cxx:715:27: note: place parentheses around the '&&' expression to silence
      this warning
    if (grab() || modal() && window != modal()) return 0;
                          ^
                  (                           )
Fl.cxx:1179:21: error: use of undeclared identifier 'NewRgn'
      Fl_Region R = NewRgn(); 
                    ^
Fl.cxx:1180:7: error: use of undeclared identifier 'SetRectRgn'
      SetRectRgn(R, X, Y, X+W, Y+H);
      ^
Fl.cxx:1181:7: error: use of undeclared identifier 'UnionRgn'
      UnionRgn(R, i->region, i->region);
      ^
Fl.cxx:1182:7: error: use of undeclared identifier 'DisposeRgn'; did you mean
      'DisposePtr'?
      DisposeRgn(R);
      ^~~~~~~~~~
      DisposePtr
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Headers/MacMemory.h:1188:1: note: 
      'DisposePtr' declared here
DisposePtr(Ptr p)                                             __OSX_AVAI...
^
Fl.cxx:1182:18: error: cannot initialize a parameter of type 'Ptr'
      (aka 'char *') with an lvalue of type 'Fl_Region'
      (aka 'OpaqueRgnHandle *')
      DisposeRgn(R);
                 ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Headers/MacMemory.h:1188:16: note: 
      passing argument to parameter 'p' here
DisposePtr(Ptr p)                                             __OSX_AVAI...
               ^
In file included from Fl.cxx:1214:
./Fl_mac.cxx:91:1: error: unknown type name 'CursHandle'; did you mean
      'CharsHandle'?
CursHandle fl_default_cursor;
^~~~~~~~~~
CharsHandle
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/Carbon.framework/Frameworks/HIToolbox.framework/Headers/TextEdit.h:352:41: note: 
      'CharsHandle' declared here
typedef CharsPtr *                      CharsHandle;
                                        ^
In file included from Fl.cxx:1214:
./Fl_mac.cxx:106:8: error: unknown type name 'CursPtr'; did you mean 'CharsPtr'?
static CursPtr default_cursor_ptr;
       ^~~~~~~
       CharsPtr
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/Carbon.framework/Frameworks/HIToolbox.framework/Headers/TextEdit.h:351:41: note: 
      'CharsPtr' declared here
typedef char *                          CharsPtr;
                                        ^
In file included from Fl.cxx:1214:
./Fl_mac.cxx:107:8: error: unknown type name 'Cursor'
static Cursor default_cursor;
       ^
./Fl_mac.cxx:471:15: error: use of undeclared identifier 'GetMenuItemRefCon'
  OSErr rrc = GetMenuItemRefCon( cmd->menu.menuRef, cmd->menu.menuItemIn...
              ^
./Fl_mac.cxx:475:23: warning: cast to 'Fl_Menu_Item *' from smaller integer type
      'UInt32' (aka 'unsigned int') [-Wint-to-pointer-cast]
    Fl_Menu_Item *m = (Fl_Menu_Item*)ref;
                      ^
./Fl_mac.cxx:479:7: error: use of undeclared identifier 'SetItemMark'
      SetItemMark( cmd->menu.menuRef, cmd->menu.menuItemIndex, (m->flag...
      ^
./Fl_mac.cxx:491:9: error: use of undeclared identifier 'SetItemMark'
        SetItemMark( cmd->menu.menuRef, i, ( j->flags & FL_MENU_VALUE ) ...
        ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
2 warnings and 20 errors generated.
make[1]: *** [Fl.o] Error 1
make: *** [all] Error 1
asdfghjklm
  • 643
  • 2
  • 7
  • 18
  • 4
    These are linking errors - the compiler expects object files/libraries to link to that provides the implementation of what's declared in `Graph.h`. In that source code dir, there's implementations for all of these (`Graph.cpp`, `Simple_window.cpp`, etc.) You need to compile these files as well and include them in your linking step. – Joe Feb 28 '18 at 21:02
  • I tried to compile the project, but it doesn't work. You can see the terminal output above. – asdfghjklm Feb 28 '18 at 22:03
  • Which book? Is it this one: https://stackoverflow.com/questions/15558519/how-can-i-use-stroustrups-graphics-libraries-simple-window-h-graph-h-in – Kenny Ostrom Feb 28 '18 at 22:38
  • Yes, this is the book. – asdfghjklm Mar 02 '18 at 20:20

0 Answers0