Hello World
=============

This guide will walkthrough the creation and cross-compilation of a Hello World executable intended to run on the phyCORE-i.MX8X.

.. note:: In order to follow this guide, you must first :ref: `installSDK-8X` and source the cross compilation environment.

Let's make a project directory to contain the Hello World source code:

.. code-block:: none
  :caption: Host (Ubuntu)

  mkdir ~/helloworld-project
  cd ~/helloworld-project

Create the main Hello World application source code file using your favorite text editor:

.. code-block:: none
  :caption: Host (Ubuntu)

  vim helloworld.c

Edit the contents of the file to reflect the following and remember to save your changes when you are done!

.. code-block:: none
  :caption: helloworld.c

  #include <stdio.h>

  int main()
  {
        printf("Hello World!\n");
  }

Cross-Compile the Hello World project:

.. code-block:: none
  :caption: Host (Ubuntu)

  $CC -O helloworld.c -o helloworld

You should now see an executable of the name "helloworld" in the current working directory. Remember that this file was cross-compiled so it won't work as expected if you try to execute it on your Ubuntu Host Machine. We can confirm the target architecture of the binary like this:

.. code-block:: none
  :caption: Example Output

  user@ubuntu:~/helloworld-project$ file helloworld
  helloworld: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, BuildID[sha1]=565c9da2e79cc69861115a358f21c4e8c01ba9fa, for GNU/Linux 3.14.0, not stripped

Now, transfer the executable to the phyCORE-i.MX8X while it is booted into Linux. Check out the guide, :ref: `cpyfiletodevice-8X`, for a bunch of options on how to do this. I recommend just quickly copying the "hello" file to a USB thumb drive to transfer files to the running target or, if you have time, setting up a network file sharing for long term development.

Once the file is transferred to the phyCORE-i.MX8X, navigate to the directory containing it using the target console and run the binary:

.. code-block:: none
  :caption: Target (Linux)

  ./helloworld

.. code-block:: none
  :caption: Exmaple Output

  root@imx8x-phycore-kit:~# ./helloworld
  Hello World!