FLTK在linux下的编译安装过程,让大家少走弯路

  今天整整花了一天的时间才算在linux下安装完fltk。我见网上对fltk2.0的评价很好,我就下载了fltk-2.0.x-alpha-r9296.tar.bz2。然后我就开始了编译。打开README.unix。定位到下面:


You can get the exact setup you need. Options that you can pass to
./configure include:

–disable-xft – Don’t use Xft/XRender (anti-aliased fonts)
–enable-debug – Enable debugging code & symbols
–enable-shared – Enable generation of shared libraries

–prefix=/dir – Set the directory prefix for files
[default = /usr/local]
–bindir=/path – Set the location for executables
[default = /usr/local/bin]
–libdir=/path – Set the location for libraries
[default = /usr/local/lib]
–includedir=/path – Set the location for include files.
[default = /usr/local/include]

To install the library, become root and type “make install”. This
will copy the “fluid” executable to “bindir”, the header files to
“includedir”/fltk, and the library files to “libdir”.

这点英语,在linux下安装过软件的都懂的。

于是乎,我就解压:

$ tar xvf fltk-2.0.x-alpha-r9296.tar.bz2

接着configure

$ ./configure –disable-xft –enable-debug –enable-shared

几分钟后,就make了

$ make

make中途出错了,问题出在fltk/GL/文件夹下的少了一些文件。然后我就走了许多弯路。结果还是以失败告终。下面说重点的。

  按照上面的操作总是会有些问题的。我找了许多资料,就这个资料ubuntu安装FLTK)帮助了我。虽然人家的是1.x版本的,但是在linux下安装东西都差不多。这里我同样建议:如果安装的代码库,尽量自己设定库文件的目录。

这里,我创建了如下的目录用来存放fltk库。

$ mkdir /home/hanxi/reference/fltk2

$ cd /home/hanxi/reference/fltk2

$ mkdir {bin,lib,include}

  为库设定好目录后,我就可以来安装,先进入到源代码的目录,然后执行下面语句进行configure

$ ./configure –enable-debug –disable-gl –enable-shared –enable-threads –enable-xdbe –enable-xft –bindir=/home/hanxi/reference/fltk2/bin –libdir=/home/hanxi/reference/fltk2/lib –includedir=/home/hanxi/reference/fltk2/include –prefix=/home/hanxi/reference/fltk2

主要是注意后面路径别写错了。然后执行mak语句,注意了,中间还是会有那个GL目录缺失文件的错误。所以使用下面的命令

$ make -ki

几分钟过后,执行make install

$ make install

到这里,就算安装成功了。下面弄个例子试一试:

  测试代码:

#include <fltk/Window.h>#include <fltk/Widget.h>#include <fltk/run.h>using namespace fltk;int main(int argc, char **argv){    Window *window = new Window(800, 600);    window->begin();    Widget *box = new Widget(20, 40, 260, 100, "Hello, World!");    box->box(UP_BOX);    box->labelfont(HELVETICA_BOLD_ITALIC);    box->labelsize(36);    box->labeltype(SHADOW_LABEL);    window->end();    window->show(argc, argv);    run();    return 1;}

makefile文件:

test: test.cpp    g++ test.cpp -o test -I/home/hanxi/reference/fltk2/include -L/home/hanxi/reference/fltk2/lib -lfltk2 -lXext -lXinerama -lXft -lX11 -lXi -lmclean:    rm *.o

运行效果:

后记:在国内,linux下安装东西的教程还是比较少的。不过学会了读帮助文档的话这些根本就不是问题。谢谢您看到这里,希望您会有所收益。

参考资料:

[1] ubuntu安装FLTK

[2] 跟我一起写 Makefile(一)

本文链接



You must enable javascript to see captcha here!

Copyright © All Rights Reserved · Green Hope Theme by Sivan & schiy · Proudly powered by WordPress

无觅相关文章插件,快速提升流量