cross compiling applications over directfb statically

In a previous post, I discussed about how to cross compile directfb for ARM. In this post, We are going to cross compile applications based on directfb libraries.

This is a sample c program which uses directfb.
directfb.c

#include <stdio.h>
#include <unistd.h>

#include <directfb.h>

static IDirectFB *dfb = NULL;

static IDirectFBSurface *primary = NULL;

static int screen_width  = 0;
static int screen_height = 0;

#define DFBCHECK(x...)                                         
  {                                                            
    DFBResult err = x;                                         
                                                               
    if (err != DFB_OK)                                         
      {                                                        
        fprintf( stderr, "%s <%d>:nt", __FILE__, __LINE__ ); 
        DirectFBErrorFatal( #x, err );                         
      }                                                        
  }

int main (int argc, char **argv)
{
  DFBSurfaceDescription dsc;
  DFBCHECK (DirectFBInit (&argc, &argv));
  DFBCHECK (DirectFBCreate (&dfb));
  DFBCHECK (dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN));
  dsc.flags = DSDESC_CAPS;
  dsc.caps  = DSCAPS_PRIMARY | DSCAPS_FLIPPING;
  DFBCHECK (dfb->CreateSurface( dfb, &dsc, &primary ));
  DFBCHECK (primary->GetSize (primary, &screen_width, &screen_height));
  DFBCHECK (primary->FillRectangle (primary, 0, 0, screen_width, screen_height));
  DFBCHECK (primary->SetColor (primary, 0x80, 0x80, 0xff, 0xff));
  DFBCHECK (primary->DrawLine (primary,
			                      0, screen_height / 2,
			       screen_width - 1, screen_height / 2));
  DFBCHECK (primary->Flip (primary, NULL, 0));
  sleep (5);
  primary->Release( primary );
  dfb->Release( dfb );
  return 23;
}

To compile an application statically using directfb we should include few compiler directives informing gcc about required libraries. The compiler directives needed can be found using arm-linux-directfb-config command in $PREFIX/bin/ directory. Here, $PREFIX is the directory where you installed directfb.

./arm-linux-directfb-config --libs --cflags --system=fbdev

-I/usr/dfb/include/directfb -D_REENTRANT
-static
/usr/dfb/lib/directfb-1.2-0/wm/libdirectfbwm_default.o
/usr/dfb/lib/directfb-1.2-0/systems/libdirectfb_fbdev.o
-L/usr/dfb/lib -ldirectfb -lfusion -ldirect -lpthread

Use these directives in the same order to compile the application,

arm-linux-gcc -o sairamfirst sairamfirst.c -I/usr/dfb//include/directfb -D_REENTRANT -static /usr/dfb/lib/directfb-1.2-0/wm/libdirectfbwm_default.o /usr/dfb/lib/directfb-1.2-0/systems/libdirectfb_fbdev.o -L/usr/dfb//lib -ldirectfb -lfusion -ldirect -lpthread -ldl

In your root file system, create tty0 and fb0 device files.

mknod tty0 c 4 0
mknod fb0 c 29 0

Now copy the directories in $PREFIX to your rootfs and try executing this application. It should draw a horizontal line in the center of the screen.

tejainece

Ravi Teja is a technology entrepreneur with interest in Embedded Systems, Software engineering, Operating Systems, Web development, Cloud computing, Machine learning, etc.

More Posts - Website

Follow Me:
LinkedInGoogle Plus

  • When I compile your demo application, I get a warning:
    “Using ‘getaddrinfo’ in statically linked applications requires at runtime the shared libraries from the glibc version used for linking”
    And when I run the programe the output is
    “(*) DirectFB/Core: Single Application Core. (2010-11-28 17:21)
    Segmentation fault”
    I use DirectFb version 1.0.0 and follow your topic.
    Thank for your post.

  • hi,
    Are you building a root file system? If yes, You have to copy all the required libraries from the tool chain you used to compile directfb. Refer this article on how to create rootfs with libraries,

    http://geekwentfreak.wordpress.com/2010/10/23/creating-rootfs-using-dynamically-linked-busybox/

    If you have further problems please ping me at tejainece@gmail.com

    I took the original sample directfb application source code from here,

    http://www.directfb.org/docs/DirectFB_Tutorials/simple.html

  • Hi,
    I am a newbie to DirectFB programming. I have downloaded the DirectFB-1.4.9 installed(in desktop) and i am able to run the example programs successfully. I have shipped the DirectFB with the required libraries on to my target platform. I am able to run the exe but its is not working as it’s desired. i.e: I tried the above mentioned program (drawline on center of the screen) on my desktop its working perfectly.In the target platform program is executing it’s executing with out any problem but it’s not drawing the line on center of the screen (I guess the exe is having the desktop monitor screen parameters only). I tried static as well as dynamic compilation options but still there is no difference at all. Could you some pointer on this.

    Thank you,

  • When I compile your demo application,

    if i give this command:
    ./arm-uclinuxeabi-directfb-config –libs –cflags –system=fbdev

    output:
    -I/opt/n/dfb//include/directfb -D_REENTRANT
    -static
    /opt/n/dfb//lib/directfb-1.0-0/wm/libdirectfbwm_default.o
    /opt/n/dfb//lib/directfb-1.0-0/systems/libdirectfb_fbdev.o
    -L/opt/n/dfb//lib -ldirectfb -lfusion -ldirect -lpthread

    after this i give next command:

    arm-uclinuxeabi-gcc -o sairamfirst directfb.c -I/opt/n/dfb//include/directfb -D_REENTRANT -static /opt/n/dfb/lib/directfb-1.0-0/wm/libdirectfbwm_default.o /opt/n/dfb/lib/directfb-1.0-0/systems/libdirectfb_fbdev.o -L/usr/dfb//lib -ldirectfb -lfusion -ldirect -lpthread -ldl

    output:
    “arm-uclinuxeabi-gcc: /opt/n/dfb/lib/directfb-1.0-0/systems/libdirectfb_fbdev.o: No such file or directory”
    this error is coming.

    if i go to //opt/n/dfb//lib/directfb-1.0-0/ there is no system folder at all.

    Can i know what was the problem

    Thanks, in advance..

    Regards,
    Harish. G.