2. Create and build a "Hello world" application

Follow these steps to create and build a "Hello world" application:

  1. Create a directory called hello_world:
  2. ~> mkdir hello_world
  3. Inside the hello_world directory, create a file named hello-world.c:
  4. ~> cd hello_world
    ~> touch hello-world.c
  5. Edit the hello-world.c file with the following contents:
  6. hello-world.c 
    #include <stdio.h>
    #include <unistd.h>
     
    int main(int argc, char *argv[]){
        int i;
     
        for (i = 1; i <= 10; i++) {
        printf("%d - Hello world!\n", i);
            sleep(1);
        }
     
        return 0;
    }
  7. Create a makefile file inside the hello_world directory:
  8. ~> touch Makefile
  9. Edit the file Makefile with the following contents:
  10. Makefile 
    BINARY := hello-world
    CFLAGS += -Wall -O0
     
    .PHONY: all
    all: $(BINARY)
     
    $(BINARY): hello-world.o
     
    .PHONY: clean
    clean:
    -rm -f *.o $(BINARY)
  11. Before building the code, export the toolchain environment:
  12. ~> . /opt/dey/2.2-r3/environment-setup-cortexa7hf-neon-dey-linux-gnueabi
  13. Cross-compile the code using make.
  14. ~> make

    Note If you are building a Qt application, run qmake before cross-compiling:

    ~> qmake

    The binary file, hello-world, is generated inside the directory hello_world.

    
    ~> ls -l
    total 28
    -rwxrwxr-x 1 user user 12084 dic 18 12:39  hello-world
    -rw-rw-r-- 1 user user   199 dic 18 12:39 hello-world.c
    -rw-rw-r-- 1 user user  4968 dic 18 12:39 hello-world.o
    -rw-rw-r-- 1 user user   189 dic 18 12:39 Makefile