我一直试图让C ++图形工作,因为我有一个涉及此的任务。我很确定我的代码没有错误,但我在编译错误方面遇到了麻烦。我从这本书中拿走了这个片段,它仍然不起作用。
我包含的头文件: http://www.stroustrup.com/Programming/Graphics/
我还下载了FLTK-1.1.9,我将FL文件夹复制到我的项目目录中,因为我对请求它们的文件有一些问题。我没有安装FLTK-1.1.9,因为我被告知我不需要。
我正在使用CLion,但我也尝试使用clang(Apple LLVM版本8.1.0(clang-802.0.42))进行编译。
#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
当尝试使用cmake编译目录时,这是我收到的错误。我刚刚将XCODE更新到最新版本。
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