Embedded Linux a simple hello program compilation and running example

Embedded Linux a simple hello program compilation and running example

Because the embedded cpu speed is relatively slow, so the embedded linux program is compiled on the pc. The compiler on the pc needs the compiler tools of embedded linux on the one hand, and on the linux system on the other hand. The way to compile embedded linux programs is called cross-compilation, and the compiler tool for embedded linux is called cross-compilation tool chain. Here, a simple hello program of Huawei HiSilicon CPU is used as an example to complete the familiarization process.

1. Build an embedded Linux cross-compilation environment
2. Set environment variables
3. Compile the program
4. Copy the execution program to the embedded board
5. Execute

1. Build an embedded Linux cross-compilation environment.
This is to decompress the compressed package
Insert picture description here
Linux and decompress tar -jxvf arm-hisiv300-linux.tar.bz2

2. Setting environment variables
Generally, embedded linux engineers have more than one compilation tool,
so they often use temporary designation
export PATH=~/Desktop/aiot/arm-hisiv300-linux/bin

3. Write the program and compile
hello_haisi.c

#include <stdio.h>

int main()
{
    
    
	printf("hello haisa\n");
	return 0;
}

The compilation is the same as the original linux compilation, that is, replace gcc with gcc in the tool chain
arm-hisiv300-linux-uclibcgnueabi-gcc hello_haisi.c -o hello

4, the copy execution program embedded board
connecting cable can be used FTP, NFS file sharing networks and other transmission mode, where a direct copy to disk u
and u disk embedded plug above the machine linux
embedded linux above open serial terminal
linked Load the u disk mount /dev/sda1 /mnt and
enter the u disk directory cd /mnt/

5. The execution is the
same as on the PC Linux. /
hello

Guess you like

Origin blog.csdn.net/u010835747/article/details/105219123