Project

General

Profile

Example - Hello World

Objective

This example creates, compiles, and runs a C Hello World program and demonstrates that the development kit includes a primitive development system and can run user-created applications.

Prerequisites

  • Basic knowledge of the "vi" editor.
    • Or the ability to copy-and-paste

      The vi provided in the Development Kit is a BusyBox version of vi and is very limited in order to be tiny. Many commands and options are not implemented.

Steps

  • Create the hello.c source file.
    • Using vi
      • Start vi. (enter vi hello.c)
      • Enter insert mode: press the i key
      • Enter the following text. (or copy and paste)
        #include <stdio.h>
        
        int main ()
        {
            printf ("Hello World!!\n");
        }
        
      • Exit insert mode: press the escape key (esc)
      • Save the file: enter :w
      • Exit the editor: enter :q
    • Using cat
      cat <<EOF >hello.c
      #include <stdio.h>
      
      void main()
      {
          printf ("Hello World!!\n");
      }
      EOF
      
  • Compile and link the program
    gcc -c hello.c
    gcc hello.o -o hello
    
  • Run the program
    ./hello
    

    This produces the following output:
    Hello World!!
    
  • The complete session:
    root@mitysom-am57x:~# cat <<EOF >hello.c
    > #include <stdio.h>
    >
    > void main()
    > {
    >     printf ("Hello World!!\n");
    > }
    > EOF
    root@mitysom-am57x:~# gcc -c hello.c
    root@mitysom-am57x:~# gcc hello.o -o hello
    root@mitysom-am57x:~# ./hello
    Hello World!!
    root@mitysom-am57x:~# 
    

Conclusion

In this example you have created, compiled, and run a C Hello World program and demonstrated that the development kit includes a basic development system and can run user-created applications.

Go to top
Add picture from clipboard (Maximum size: 1 GB)