ubuntu16.04 (64-bit) establishes a cross-compilation environment and configures the compiled kernel

installation steps

1. Prepare the tool installation directory

Store the compressed package gcc-linaro-arm-linux-bnueabihf-4.9-2014.07_linux.tar in a directory. This directory is the directory you will decompress later. This directory cannot be deleted casually. My storage path It is /home/aldrich/arm, as shown in the figure below, remember this path, and it will be used later.

 

 

  1. .tar.gz 和.tgz
  2. 解压:tar zxvf FileName.tar.gz
  3. 压缩:tar zcvf FileName.tar.gz DirName
 

2. Install the software

Use the tar command: tar zxvf arm-linux-gcc-4.3.2.tgz to decompress and install arm-linux-gcc-4.3.2.tgz in the software folder to the current directory. From the figure below, you can see that the decompression is successful, and the decompressed files are stored in

  1. /home/aldrich/arm/arm-linux-gcc-4.3.2
 

Under the folder, as shown in the following figure, this storage path can be remembered, as shown in the following figure

 

 

3. Configure system environment variables

Sit down and popularize before configuring the environment:

The difference between profile and bashrc in different directories of Ubuntu

/etc/profile   This file sets the environment information for each user of the system. When the user logs in for the first time, this file is executed, and the shell settings are collected from the configuration files in the /etc/profile.d directory.

/etc/bash.bashrc   executes this file for every user running the bash shell, and is read when the bash shell is opened.

~/.bash_profile   Each user can use this file to input the shell information dedicated to their own use. When the user logs in, the file is executed only once. By default, he sets some environment variables and executes the user's .bashrc file.

~/.bashrc   This file contains bash information specific to your bash shell and is read when logging in and every time a new shell is opened.

~/.bash_logout   This file is executed every time you exit the system (exit the bash shell).

In addition, the variables (global) set in /etc/profile can act on any user, while the variables (local) set in ~/.bashrc can only inherit the variables in /etc/profile, they are "father and son" "relation.

~/.bash_profile   is an interactive, login method to enter bash to run.

~/.bashrc   is an interactive non-login way to enter bash to run.

Usually the two settings are roughly the same, so usually the former will call the latter.

Next, configure the system environment variables and add the path of the cross-compilation toolchain to the environment variable PATH, so that these tools can be used in any directory. Note down the installation path in the previous step, use the command: vim /home/aldrich/.bashrc to edit the .bashrc file and add environment variables.

Add in the last line of this file:

  1. export PATH=$PATH:/home/aldrich/arm/arm-linux-gcc-4.3.2/bin
 

This path is the path where the bin directory is located. Maybe yours is different, just fill in according to your actual directory, as shown below

 

Just write and save

4. Make environment variables take effect

Use the command: source /home/aldrich/.bashrc to make environment variables take effect

5. Check whether the environment variable is set successfully

Enter the command arm-linux on the terminal and press the Tab key, you can see the following figure, indicating that the environment variable setting is successful

 

 

 

6. Install the 32-bit library compatibility package

After entering the command, the following error message appears:

  1. /home/aldrich/arm/arm-linux-gcc-4.3.2/bin/arm-linux-gcc:
  2. line 3:
  3. /home/aldrich/arm/arm-linux-gcc-4.3.2/bin/arm-none-linux-gnueabi-gcc:No such file or directory
 

 

It is said that the reason for this problem is that Ubuntu16.04 uses 64-bit. The previous solution is to use the command:

sudo apt-get install ia32-libs install some 32-bit libraries

 

The above interface appears because the Ubuntu16.04 version no longer supports the ia32-libs package, but uses the lib32ncurses5 and lib32z1 packages instead, so it should be installed and executed in the Ubuntu16.04 version:

  1. sudo apt-get install lib32ncurses5 lib32z1
 

After installing the 32-bit library, use the command: arm-linux-gcc -v, this time it is successful, as shown below

 

 

 

8. Cross-compilation tool verification

Compile a hello.c file

  1. #include<stdio.h>
  2. int main()
  3. {
  4.     printf("hello world!\n");
  5. }
 

Use the command: arm-linux-gcc hello.c -o hello to see if the compilation is successful

 

It can be seen that the binary file has been successfully generated. At this point, the cross-compilation tool is equipped with the length. .

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325899849&siteId=291194637