每个人。我正在学习 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 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' ... ...