cross compiling applications using directfb library

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;
}

First we have to configure pkg-config to point to our directfb libraries.

PREFIX=/home/sairam/Public/directfb
export LD_LIBRARY_PATH=$PREFIX/lib
export PKG_CONFIG_PATH=$LD_LIBRARY_PATH/pkgconfig

Now compile the application,

arm-linux-gcc `pkg-config --cflags directfb` -o directfb directfb.c `pkg-config --libs directfb`

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

  • If i run the executable app on target means i am getting segmentation fault.

    Can i know what was the problem.

    Thanks in advance,

    Regards,

    Harish. G