Hello World
This guide will walkthrough the creation and compilation of a Hello World executable intended to run directly on the phyCORE-AM64x Development Kit running Linux.
Write your Hello World Code
Let’s make a project directory to contain the Hello World source code:
sh-phyboard-electra-am64xx-2:~# mkdir ~/helloworld-project
sh-phyboard-electra-am64xx-2:~# cd ~/helloworld-project
Create the main Hello World application source code file using your favorite text editor, this guide will leverage ‘vi’ but ‘nano’ is a more beginner friendly option:
sh-phyboard-electra-am64xx-2:~# vi helloworld.c
Edit the contents of the file to reflect the following and remember to save your changes when you are done!
#include <stdio.h>
int main()
{
printf("Hello World!\n");
}
Note
You can follow the same steps on the host machine. This documentation uses the target prompt as an example.
Native Compilation (On the Target)
This section requires a native compiler to be installed. Refer to Install a Compiler for setup instructions. Afterward, complete the steps in ‘Write your HelloWorld Code’ on the target and compile the project.
sh-phyboard-electra-am64xx-2:~# gcc helloworld.c -o helloworld
Run the binary:
sh-phyboard-electra-am64xx-2:~# ./helloworld
You should see the following output:
sh-phyboard-electra-am64xx-2:~# ./helloworld
Hello World!
Cross-Compilation (On a Linux Host Machine)
Just like compiling on the target, the host system requires the SDK to be pre-installed. Refer to Install The SDK for setup instructions, and ensure you source it afterward.
Recreate the helloworld.c
file on the host system and compile it using the following command:
sh-host:~$ $CC helloworld.c -o helloworld
Once built, you can confirm the target architecture the binary is intended for using the ‘file’ utility:
sh-host:~$ file helloworld
helloworld: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, BuildID[sha1]=71f34ddf90d981cb429087646d6b39c629dec800, for GNU/Linux 3.7.0, with debug_info, not stripped
You’ll notice errors if you try to run this binary on the Host Machine. Check out the Copying Files to the Device Guide to help you transfer it to the phyCORE-AM64x Development Kit such that you can execute it.