Follow these steps to create and build a "Hello world" application:
-
Create a directory called
hello_world
:$ mkdir hello_world
-
Inside the
hello_world
directory, create a file namedhello-world.c
:$ cd hello_world $ touch hello-world.c
-
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; }
-
Create a makefile file inside the
hello_world
directory:$ touch Makefile
-
Edit the file Makefile with the following contents:
MakefileBINARY := hello-world CFLAGS += -Wall -O0 .PHONY: all all: $(BINARY) $(BINARY): hello-world.o .PHONY: clean clean: -rm -f *.o $(BINARY)
-
Before building the code, export the toolchain environment:
$ . /opt/dey/3.2-r3/ccimx6qpsbc/environment-setup-cortexa9t2hf-neon-dey-linux-gnueabi
-
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 directoryhello_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