如何在 Ubuntu 12.10 的 Netbeans 7.3 中使用 Stroustrup 的图形库(Simple_window.h、Graph.h、...)?

How can I use Stroustrup's graphics libraries (Simple_window.h, Graph.h, ...) in Netbeans 7.3 in Ubuntu 12.10?

本文关键字:Simple 图形库 window Stroustrup Graph Ubuntu Netbeans      更新时间:2023-10-16

每个人。我正在学习Bjarne Stroustrup的"使用C++编程原理和实践"一书。我在Ubuntu 12.10中使用Netbeans 7.3。我想在本书的第12章中构建并运行这个简单的图形程序。程序如下:

#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    
}

我两天内无法构建此程序。我在中添加了所有图形库http://www.stroustrup.com/Programming/Graphics/我的项目。我还成功地安装了FLTK-1.1.10,并将其配置为Netbeans。所有关于FLTK的程序都能很好地在Netbeans中运行。但是,当涉及到构建和运行上面显示的程序时,会出现许多错误。错误如下:"未定义引用…"。如何在Netbeans中解决此问题?

错误发生如下:

g++-o dist/Debug/GNU-Linux-x86/cpapplication_3 build/Debug-GNU-Linux-x86/GUI.o build/Debug/GNU-Lianux-x86/Graph.o build/Debbug/GNU-Liinux-x86/Simple_window.o build/Deebug/GNU-Linux-x86/window.o uild/Debug/GNU-Linux-x86/main.o-L..//下载/fltk-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(:在函数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.cx:(.text+0x38(:未定义对XParseColor' ../../Downloads/fltk-1.1.10/lib/libfltk.a(Fl_get_system_colors.o): In function Fl_parse_color的引用(char const*、unsigned char&、unsignedchar&unsigned char&(':Fl_get_system_colors.cxx:(.text+0x2cd(:对"XParseColor"的未定义引用。。。

看起来您需要指定要链接的X库:

 -lXext -lX11

如果您下载了FLTK 1.3.3,则include的名称与以前的版本不同。因此,在Bjarne Stroustrup的书的第1203页,关于如何安装fltk的教程不再好了,因为它们已经改变了很多。以下是关于如何为VS安装它以及如何在Win32项目中设置它的教程。http://www.c-jump.com/bcc/common/Talk2/Cxx/FltkInstallVC/FltkInstallVC.html在fltk网站上,有一些教程(解释不如Bjarne好,但没关系(。