DESK-RZ-L/Development/Application examples/Hello World C example

From DAVE Developer's Wiki
Jump to: navigation, search
History
Issue Date Notes
2025/12/19 DESK-RZ-L-1.x.x release



Hello word example[edit | edit source]

Below is an example on C code displaying the classic Hello World! message on the target serial console.

This example shows how to use the arm cross-compiler using the environment configured for this purpose.

Setting the cross-compiler[edit | edit source]

  • start the Linux development VM and log in to the system
  • open a terminal window and cd into your source code directory
dvdk@vagrant:~/desk-rz-l$ mkdir myproject
dvdk@vagrant:~/desk-rz-l$ cd myproject/
dvdk@vagrant:~/desk-rz-l/myproject$ vi hello.c
dvdk@vagrant:~/desk-rz-l/myproject$ cat hello.c
#include <stdio.h>

int main(){
        printf("Hello, World!\n");
        return 0;
}
  • configure the build environment
dvdk@vagrant:~/myproject$ source ~/desk-rz-l/desk-rz-l-1.0.0_env.sh
  • as you can see here below, the $CC environment variable has been properly configured for using the SDK sysroot parameter:
dvdk@vagrant:~/desk-rz-l/myproject$ echo $CC
aarch64-poky-linux-gcc -mtune=cortex-a55 -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/yocto/sdk/desk-rz-l/desk-t2h-l-1.0.0/sysroots/aarch64-poky-linux
dvdk@vagrant:~/desk-rz-l/myproject$
  • invoke the cross-compiler for compiling your source code example: the object file obtained is a proper ELF 64-bit for the target microprocessor
dvdk@vagrant:~/desk-rz-l/myproject$ $CC hello.c -Os -o hello
dvdk@vagrant:~/desk-rz-l/myproject$ file hello
hello: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-aarch64.so.1, BuildID[sha1]=01215e39e6f425d38c5da326d0a241795d01da5f, for GNU/Linux 3.14.0, with debug_info, not stripped
dvdk@vagrant:~/desk-rz-l/myproject$

Running the example on the target[edit | edit source]

Now it is enough to copy the object file in the /home/root rfs directory and boot from nfs:

dvdk@vagrant:~/desk-rz-l/myproject$ sudo cp hello ~/desk-rz-l/rootfs/home/root/.
dvdk@vagrant:~/desk-rz-l/myproject$ sudo ls -la ~/desk-rz-l/rootfs/home/root/.
total 24
drwx------ 2 root root  4096 Dec 19 08:57 .
drwxr-xr-x 3 root root  4096 Mar  9  2018 ..
-rwxr-xr-x 1 root root 13232 Dec 19 08:57 hello
dvdk@vagrant:~/desk-rz-l/myproject$ 

on the target:

desk-t2h-usd-devel login: root
root@desk-t2h-usd-devel:~# ls -la
total 24
drwx------ 2 root root  4096 Dec 19  2025 .
drwxr-xr-x 3 root root  4096 Mar  9  2018 ..
-rwxr-xr-x 1 root root 13232 Dec 19  2025 hello
root@desk-t2h-usd-devel:~# ./hello
Hello, World!
root@desk-t2h-usd-devel:~#