今天整整花了一天的時間才算在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 -lm clean: rm *.o
運行效果:
后記:在國內,linux下安裝東西的教程還是比較少的。不過學會了讀幫助文檔的話這些根本就不是問題。謝謝您看到這里,希望您會有所收益。
參考資料:
[1] ubuntu安裝FLTK