今天整整花了一天的時間才算在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(一)