首页 文章

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

提问于
浏览
0

大家 . 我正在学习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    
}

我无法 Build 这个程序2天 . 我将http://www.stroustrup.com/Programming/Graphics/中的所有图形库添加到我的项目中 . 我还成功安装了FLTK-1.1.10并将其配置为Netbeans . 关于FLTK的所有程序都在Netbeans中运行得很好 . 但是,当构建和运行上面显示的程序时,会发生许多错误 . 错误是这样的:"Undefined reference to ..." . 如何在Netbeans中解决这个问题?

错误发生如下:

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):在函数 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):未定义引用 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' ......

2 回答

  • 2

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

    -lXext -lX11
    
  • -2

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

相关问题