技术开发 频道

DirectFB 之一:PC平台编译与安装

  【IT168技术文档】上班的时候,经常听旁边的一个专门做图形库的小组提起 DirectFB, 据说今后的几年,DirectFB 将取代现有图形库,并且采用DirectFB + GTK形式,支持现有的很多基于GTK开源软件。在国内的一些论坛上,比如MiniGUI.org上,也看到过他们在做 MiniGUI + DirectFB 的文章,虽然现在不知道做到什么程度了,但是可以看出,DirectFB 还是有它的优势的。

  最近周末正好有时间,所以也想玩玩。大概的计划是: PC机上测试 -> ARM开发板上测试 -> ARM开发板gfxdriver开发。

  1. DirectFB 相关网站

  DirectFB官方主页 资料下载/文档

  DirectFB Wiki Page 很多DirectFB的文档都可以在这里找到

  2. 开发环境

  Linux: CentOS 5.1 (Kernel 2.6.18-53.el5xen)

  GCC: 4.1.2

  3. 下载 DirectFB 源代码

  DirectFB 提供3种形式的下载方式: git, cvs 和压缩包。我一般使用 git, 代码比较方便。

  # git clone git://git.directfb.org/git/directfb/core/DirectFB.git

  另外,出了DirectFB库之外,如果要支持 multi application core, 还需要 fusion 内核驱动模块;为了测试 DirectFB, 可以下载现有的测试程序:

  Fusion: linux-fusion-8.0.3.tar.gz

  Example: DirectFB-examples-1.2.0.tar.gz

  4. 编译和安装 fusion

  # cd ~/DirectFB

  # tar zxf linux-fusion-8.0.3.tar.gz

  # cd linux-fusion-8.0.3

  # make

  # sudo make install

  创建 fusion 设备文件:

  # sudo mkdir /dev/fusion

  # sudo mknod /dev/fusion/0 c 250 0

  # sudo mknod /dev/fusion/1 c 250 1

  # sudo mknod /dev/fusion/2 c 250 2

  注意:要编译 fusion 模块, 需要安装内核源码。fusion 模块默认安装到 /lib/modules/`uname -r`/ 下。

  最新的源程序可以用 git 下载:

  # git clone git://git.directfb.org/git/directfb/core/linux-fusion.git

  使用这个版本的fusion 的话, 编译 DirectFB 的时候不会提示 ../../../lib/fusion/types.h:42:2: error: #error Major version of Fusion Kernel Module too low! Upgrade your kernel. 的错误。

  5. 编译 DirectFB 库

  # cd ~/DirectFB/DirectFB

  # ./autogen.sh \

  --prefix=/usr/local \

  --disable-osx \

  --enable-x11 \

  --disable-fbdev \

  --disable-sdl \

  --disable-vnc \

  --with-gfxdrivers=none \

  --with-inputdrivers=linuxinput \

  --enable-multi \

  --enable-debug

  # make

  # sudo make install

  * 我一般将这些命令写到一个shell脚本里面。如(build-for-pc.sh)

  6. 编译错误处理

  编译 DirectFB 的时候,提示一下错误:

  # make

  ../../../lib/fusion/types.h:42:2: error: #error Major version of Fusion Kernel Module too low! Upgrade your kernel.

  这是因为:

  --- /usr/include/linux/fusion.h 文件---

  #define FUSION_API_MAJOR 8 /* Increased if backward compatibility is dropped. */

  #define FUSION_API_MINOR 0 /* Increased if new features are added. */

  #define FUSION_API_MICRO 3 /* Micro release. Bugfixes. */

  --- DirectFB/lib/fusion/types.h ---

  #define FUSION_API_MAJOR_REQUIRED 8

  #define FUSION_API_MINOR_REQUIRED 0

  #if FUSION_API_MAJOR_REQUIRED > FUSION_API_MAJOR_PROVIDED

  #error Major version of Fusion Kernel Module too low! Upgrade your kernel.

  #else

  ...

  #endif

  可以看出, FUSION_API_MAJOR_PROVIDED 没有在 /usr/include/linux/fusion.h 定义,所以 只需要将 DirectFB/lib/fusion/types.h 中 FUSION_API_MAJOR_PROVIDED 的改成 FUSION_API_MAJOR 即可。修改完之后是:

  # git diff lib/fusion/types.h

  ---------------------------------------------------------------------------

  diff --git a/lib/fusion/types.h b/lib/fusion/types.h

  index 1b862a4..3776e93 100644

  --- a/lib/fusion/types.h

  +++ b/lib/fusion/types.h

  @@ -38,11 +38,11 @@

  #define FUSION_API_MAJOR_REQUIRED 8

  #define FUSION_API_MINOR_REQUIRED 0

  -#if FUSION_API_MAJOR_REQUIRED > FUSION_API_MAJOR_PROVIDED

  +#if FUSION_API_MAJOR_REQUIRED > FUSION_API_MAJOR

  #error Major version of Fusion Kernel Module too low! Upgrade your kernel.

  #else

  -#if FUSION_API_MAJOR_REQUIRED == FUSION_API_MAJOR_PROVIDED

  -#if FUSION_API_MINOR_REQUIRED > FUSION_API_MINOR_PROVIDED

  +#if FUSION_API_MAJOR_REQUIRED == FUSION_API_MAJOR

  +#if FUSION_API_MINOR_REQUIRED > FUSION_API_MINOR

  #error Minor version of Fusion Kernel Module too low! Upgrade your kernel.

  #endif

  #endif

  ---------------------------------------------------------------------------

  再编译,OK。DirectFB 将被安装到 prefix 指定的地方(/usr/local/lib/)。

  7. 添加 /usr/local/lib/ 路径

  为了是使用DirectFB,需要将DirectFB库所在的路径添加到 系统搜索路径。否则:

  1) pkg-config 找不到 DirectFB

  2) ld 命令也找不到 DirectFB 库

  所以:

  # sudo vi /etc/ld.so.conf.d/qt-i386.conf

  添加一行: /usr/local/lib

  # sudo ldconfig

  8. 编译和安装示例程序

  # tar zxf DirectFB-examples-1.2.0.tar.gz

  # cd DirectFB-examples-1.2.0

  # ./configure \

  --prefix=/usr/local \

  --enable-debug

  # make

  # sudo make install

  示例程序如 df_andi 将被安装到 /usr/local/bin

  9. 运行示例程序

  # sudo depmod -a

  # sudo modprobe fusion # 安装 fusion 内核模块

  # cd /usr/local/bin

  # sudo ./df_andi

  ~~~~~~~~~~~~~~~~~~~~~~~~~~| DirectFB 1.3.0 |~~~~~~~~~~~~~~~~~~~~~~~~~~

  (c) 2001-2008 The world wide DirectFB Open Source Community

  (c) 2000-2004 Convergence (integrated media) GmbH

  ----------------------------------------------------------------

  (*) DirectFB/Core: Multi Application Core. (2009-03-15 08:52) [ DEBUG ]

  (*) Fusion/SHM: NOT using MADV_REMOVE (2.6.18.0 < 2.6.19.2)! [0x02061200]

  (*) Direct/Thread: Started 'Fusion Dispatch' (-1) [MESSAGING OTHER/OTHER 0/0] <10485760>...

  (*) Direct/Thread: Started 'Linux Input' (-1) [INPUT OTHER/OTHER 0/0] <10485760>...

  (*) DirectFB/Input: AT Translated Set 2 keyboard (1) 0.1 (directfb.org)

  (*) Direct/Thread: Started 'Linux Input' (-1) [INPUT OTHER/OTHER 0/0] <10485760>...

  (*) DirectFB/Input: HID 413c:3010 (2) 0.1 (directfb.org)

  (*) Direct/Thread: Started 'Linux Input' (-1) [INPUT OTHER/OTHER 0/0] <10485760>...

  (*) DirectFB/Input: PC Speaker (3) 0.1 (directfb.org)

  (*) Direct/Thread: Started 'X11 Input' (-1) [INPUT OTHER/OTHER 0/0] <10485760>...

  (*) DirectFB/Input: X11 Input 0.1 (directfb.org)

  (*) DirectFB/Genefx: MMX detected and enabled

  (*) DirectFB/Graphics: MMX Software Rasterizer 0.6 (directfb.org)

  (*) DirectFB/Core/WM: Default 0.3 (directfb.org)

  (*) X11/Window: Creating 1280x1024 RGB32 window...

  (*) X11/Display: Using XShm.

  (*) X11/Window: Creating 1280x1024 RGB32 window...

  (*) X11/Display: Using XShm.

  (*) Direct/Interface: Loaded 'FT2' implementation of 'IDirectFBFont'.

  (*) Direct/Interface: Loaded 'PNG' implementation of 'IDirectFBImageProvider'.

  (*) Direct/Interface: Loaded 'JPEG' implementation of 'IDirectFBImageProvider'.

  hoho,无数的企鹅出现了~~~~~~~~~~~

  10. 总结

  1)DirectFB 支持非Framebuffer模式,不使用 Framebuffer 也可以使用 DirectFB.

  2) 一定要记得添加 /usr/local/bin 到 /etc/ld.so.conf.d/ 里。一开始忘了,出现了一下错误:

  错误A:编译示例程序的时候

  ......

  checking for pkg-config... /usr/bin/pkg-config

  checking pkg-config is at least version 0.9.0... yes

  checking for DIRECTFB... no

  configure: error: Requested 'directfb >= 1.2.0' but version of DirectFB is 1.0.1

  *** DirectFB 1.2.0 or newer is required. The latest version

  *** of DirectFB is available from http://www.directfb.org/.

  make: *** No targets specified and no makefile found. Stop.

  关于 pkg-config 命令是如何工作的,参考 pkg-config工具.

  错误B: 运行的时候

  # sudo ./df_andi

  ./df_andi: error while loading shared libraries: libdirectfb-1.3.so.0: cannot open shared object file: No such file or directory

  # ldd df_andi

  linux-gate.so.1 => (0x0075e000)

  libdirectfb-1.3.so.0 => not found

  libfusion-1.3.so.0 => not found

  libdirect-1.3.so.0 => not found

  libpthread.so.0 => /lib/i686/nosegneg/libpthread.so.0 (0x0036d000)

  libc.so.6 => /lib/i686/nosegneg/libc.so.6 (0x001f9000)

  /lib/ld-linux.so.2 (0x001d7000)

  #! /bin/sh

  #

  # Build DirectFB library for PC

  #

  # ChangeLog:

  # V0.1 2009/03/15 Zeng Xianwei (xianweizeng@gmail.com)

  #

  prefix=/usr/local

  def_options="--prefix=${prefix}"

  fatal(){

  echo "Error: $@"

  exit 1

  }

  build_and_install(){

  ./autogen.sh \

  ${def_options} \

  --disable-osx \

  --enable-x11 \

  --disable-fbdev \

  --disable-sdl \

  --disable-vnc \

  --with-gfxdrivers=none \

  --with-inputdrivers=linuxinput \

  --enable-multi \

  --enable-debug

  make || fatal "make failed"

  sudo make install || fatal "make install failed"

  }

  build_and_install

  exit 0

0
相关文章