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

  1. Create a directory called hello_world:

    $ mkdir hello_world
  2. Inside the hello_world directory, create a file named hello-world.c:

    $ cd hello_world
    $ touch hello-world.c
  3. Edit the hello-world.c file with the following contents:

    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;
    }
  4. Create a makefile file inside the hello_world directory:

    $ touch Makefile
  5. Edit the file Makefile with the following contents:

    Makefile
    BINARY := hello-world
    CFLAGS += -Wall -O0
    
    .PHONY: all
    all: $(BINARY)
    
    $(BINARY): hello-world.o
    
    .PHONY: clean
    clean:
    	-rm -f *.o $(BINARY)
  6. Before building the code, export the toolchain environment:

    $ . /opt/dey/4.0-r6/ccimx6ulsbc/environment-setup-cortexa7t2hf-neon-dey-linux-gnueabi
  7. Cross-compile the code using make.

    $ make

    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