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 the appropriate compiler for the target, sh4-linux-gcc for ST40 Linux or st231-linux-gcc for ST231 Linux, as described below.
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-X.X/devkit/sh4/target host# mkdir -p home/<user> host# chown <user> home/<user> host% cp hello /opt/STM/STLinux-X.X/devkit/sh4/target/home/<user>/hello
target# gcc -o hello hello.cThis creates the executable file hello in the STLinux target file system directly and hence does not need to be copied to be executed.
host% st231-linux-gcc -o hello hello.cThis 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-X.X/devkit/s231/target host# mkdir -p home/<user> host# chown <user> home/<user> host% cp hello /opt/STM/STLinux-X.X/devkit/st231/target/home/<user>/hello
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# /home/<user>/hello Hello from STLinux target#
Congratulations. You have built and executed your first user program under STLinux!