问题
everyone. I am learning Bjarne Stroustrup's "Programming principle and practice using C++" book. I'm working with Netbeans 7.3 in Ubuntu 12.10. I want to build and run this simple graphics program in this book's chapter 12. The program is like this:
#include "Simple_window.h" // get access to our window library
#include "Graph.h" // get access to our graphics library facilities
int main()
{
using namespace Graph_lib; // our graphics facilities are in Graph_lib
Point tl(100,100); // to become top left corner of window
Simple_window win(tl,600,400,"Canvas"); // make a simple window
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
}
I can't build this program for 2 days. I added all graphics libraries in http://www.stroustrup.com/Programming/Graphics/ to my project. I also successfully installed FLTK-1.1.10 and configured it to Netbeans. All programs about FLTK run in Netbeans very well. But when it comes to build and run the program shown above, many errors occur. Errors are like this: "Undefined reference to ...". How can I solve this problem in Netbeans?
Errors occur like this:
g++ -o dist/Debug/GNU-Linux-x86/cppapplication_3 build/Debug/GNU-Linux-x86/GUI.o build/Debug/GNU-Linux-x86/Graph.o build/Debug/GNU-Linux-x86/Simple_window.o build/Debug/GNU-Linux-x86/Window.o build/Debug/GNU-Linux-x86/main.o -L../../Downloads/fltk-1.1.10/lib -lfltk -lfltk_forms -lfltk_gl -lfltk_images -lfltk_jpeg
../../Downloads/fltk-1.1.10/lib/libfltk.a(Fl_get_system_colors.o): In function getsyscolor(char const*, char const*, char const*, char const*, void (*)(unsigned char, unsigned char, unsigned char))':
Fl_get_system_colors.cxx:(.text+0x17): undefined reference to
XGetDefault'
Fl_get_system_colors.cxx:(.text+0x38): undefined reference to XParseColor'
../../Downloads/fltk-1.1.10/lib/libfltk.a(Fl_get_system_colors.o): In function
fl_parse_color(char const*, unsigned char&, unsigned char&, unsigned char&)':
Fl_get_system_colors.cxx:(.text+0x2cd): undefined reference to `XParseColor' ... ...
回答1:
It looks like you need to specify the X libraries to be linked in:
-lXext -lX11
回答2:
If you downloaded FLTK 1.3.3, the includes have different names than the previous versions. So at the page 1203 in Bjarne Stroustrup's book, the tutorial on how to install fltk isn't good anymore because they've changed so much. Here is a tutorial on how to install it for VS and how to set it up in a Win32 project. http://www.c-jump.com/bcc/common/Talk2/Cxx/FltkInstallVC/FltkInstallVC.html And on the fltk website, there are some tutorials there (not as well explained than Bjarne but it's alright).
来源:https://stackoverflow.com/questions/15558519/how-can-i-use-stroustrups-graphics-libraries-simple-window-h-graph-h-in