Tux
Communication
Mailing lists
Documentation
User Manual
Target board info.
Target chip info.
Support
Linux support
Bugzilla
Downloads
STLinux
Updates
Search
Google


The web
stlinux.com
Getting Started Guide
Building user programs
A simple example program - Hello World
ST Logo
Previous   Contents   Next


A simple example program - Hello World

As an example of building and executing a very simple user program, the classic "Hello World" program is given below:

#include <stdio.h>
int main(void)
{
printf("Hello from STLinux\n");
return 0;
}

Type this text in using your favorite text editor (for example, vi) and save it as hello.c. This C source file can them be compiled using either the GNU C compiler (for ST40 Linux) or the Open64 C compiler (for ST231 Linux) as described below.

ST40 cross compilation
host% sh4-linux-gcc -o hello hello.c

This creates the executable file hello in the x86 Linux host PC file system. Copy this file to the NFS mounted root file system of the target using the command:

host# cd /opt/STM/STLinux-2.0/devkit/sh4/target
host# mkdir -p home/<user>
host# chown <user> home/<user>
host% cp hello /opt/STM/STLinux-2.0/devkit/sh4/target/home/<user>/hello
ST40 native compilation
target# gcc -o hello hello.c

This creates the executable file hello in the STLinux target file system directly and hence does not need to be copied to be executed.

ST231 cross compilation
host% st231-linux-gcc -o hello hello.c

This creates the executable file hello in the x86 Linux host PC file system. Copy this file to the NFS mounted root file system of the target using the command:

host# cd /opt/STM/STLinux-2.0/devkit/s231/target
host# mkdir -p home/<user>
host# chown <user> home/<user>
host% cp hello /opt/STM/STLinux-2.0/devkit/st231/target/home/<user>/hello
Executing the target "Hello World" program

In all of the above cases, a target executable for the "Hello World" program has been created in the NFS mounted root file system of the target Linux platform.

This file can be executed from the command prompt as follows:

target# /root/hello
Hello from STLinux
target#

Congratulations. You have built and executed your first user program under STLinux.

Previous   Contents   Next
Valid HTML 4.01! Last updated: 2005/09/30 14:02:16
© Copyright STMicroelectronics Limited, 2005
Printer