Global Sources
EE Times-India
Stay in touch with EE Times India
EE Times-India > Embedded

Intro to Embedded Linux: Application development

Posted: 02 Nov 2015     Print Version  Bookmark and Share

Keywords:Linux  Raspberry Pi  kernel  compilers  debugging 

In the previous instalment, we showed how to build a Linux kernel on a Raspberry Pi Single Board Computer (SBC), as well as build it on a much faster development system. There are some advantages to building on our target system, namely that we are using development tools and the environment on the target. When we develop on another system, we have to use cross compilers and a copy of the target environment, which makes this somewhat more complex. But a cross-development environment is usually much faster than an embedded target, with much more disc and memory space. With many embedded Linux projects, it simply isn't possible to build on the target.

We are continuing our series on how to get started using Embedded Linux. The previous installment can be found here.

Let's take a look at software development for an Embedded Linux system, our Raspberry Pi. We are first going to write the traditional "Hello World" program and compile it on the RPi, then we will do the same on the development host, using the cross-development tools we installed to build the Linux kernel.

Compiling on the target
Log in to your RPi system, either on the system console, or like I do, using ssh in a window on my development system. Create a directory named "projects" under your home directory and cd into it. Now we can use an editor (vi or nano) to create the source file named "hello.c":

int main (void)
    printf ("Hello World!\n");
    return 0;

We can compile this using the following command:

$ gcc -o hello hello.c

This says to run gcc, the GNU C Compiler, to create an executable program named "hello" using the source file named "hello.c". If everything is OK, you will get a prompt. Like many other Linux commands, if there are no errors, gcc doesn't say anything.

We can run this command from the command line and it will generate the expected output.

$ ./hello
Hello World!

You need to specify a full or partial path to the "hello" program. In this case, we enter "./" to say that the program can be found in the current directory. If you don't specify a full or partial path, the bash command shell will search the directories listed in the $PATH environment variable for the program. In this case, bash will say "command not found".

This seems simple, but there's quite a bit going on under the covers. If you add the "-v" option to the gcc command it will list all of the steps that it takes to compile, assemble, and link the program. GCC knows where to find the "stdio.h" include file as well the library which includes the "printf" function and others needed to create an executable program. If you want to see the directories which gcc will search for include files, run this command:

$ cpp -Wp,-v /dev/null

You will see that among others, gcc will search /usr/include where it will find stdio.h. The libraries which are searched can be listed by running gcc with the -print-search-dirs option.

Compiling on the host
Let's do the same on our development system. Create a projects directory and create the "hello.c" source file. (Alternately, you can use scp to copy the file from the RPi to your development system.)

1 • 2 Next Page Last Page

Comment on "Intro to Embedded Linux: Application..."
*  You can enter [0] more charecters.
*Verify code:


Visit Asia Webinars to learn about the latest in technology and get practical design tips.


Go to top             Connect on Facebook      Follow us on Twitter      Follow us on Orkut

Back to Top