0

每个人。我正在学习 Bjarne Stroustrup 的“Programming principle and practice using 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    
}

我无法在 2 天内构建此程序。我将http://www.stroustrup.com/Programming/Graphics/中的所有图形库添加到我的项目中。我还成功安装了 FLTK-1.1.10 并将其配置为 Netbeans。所有关于 FLTK 的程序都在 Netbeans 中运行得很好。但是在构建和运行上面显示的程序时,会出现很多错误。错误是这样的:“未定义的引用...”。如何在 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 toXGetDefault' Fl_get_system_colors.cxx:(.text+0x38): 对XParseColor' ../../Downloads/fltk-1.1.10/lib/libfltk.a(Fl_get_system_colors.o): In functionfl_parse_color的未定义引用(char const*, unsigned char&, unsigned char&, unsigned char&)': Fl_get_system_colors.cxx:(.text+0x2cd): undefined reference to `XParseColor' ... ...

4

2 回答 2

2

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

 -lXext -lX11
于 2013-03-21T21:54:41.423 回答
-2

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

于 2017-08-18T00:33:22.700 回答