The construction of ubantu16.04 arm cross compiling environment

Install arm-linux-gcc-4.4.3 on Ubuntu 16.04

I. unzip the installation package:

sudo tar -zxvf arm-linux-gcc-4.4.3.tar.gz -C /

Note that there is a space after C, so the extracted file is under the path of / opt / friendlyarm / toolchain / 4.4.3

3. Create a new arm directory under the / usr/local directory, and copy 4.4.3 under the path / opt / friendlyarm / toolchain / to the arm Directory:

cd /usr/local

sudo mkdir arm

sudo chmod 777 arm

sudo cp -r /opt/FriendlyARM/toolschain/4.4.3 /usr/local/arm

4. Modify the environment variable to add arm linux GCC to the PATH:

Method 1: modify the / etc/bash.bashrc file, which is only applicable to the current user

sudo gedit /etc/bash.bashrc

Add export PATH=$PATH:/usr/local/arm/4.4.3/bin at the end

Save, exit, and refresh the environment variables to take effect:

source /root/.bashrc

Method 2: modify the / etc/profile file, which is applicable to all users

sudo gedit /etc/profile

Add export PATH=$PATH:/usr/local/arm/4.4.3/bin at the end

Save, exit, and refresh the environment variables to take effect:

source /etc/profile

Method 3: modify the / etc/environment file

sudo gedit /etc/environment

Add / usr/local/arm/4.4.3/bin at the end

Save, exit, and restart the system

V. check whether the environment variables are added correctly:

echo $PATH

If / usr/local/arm/4.4.3/bin can be displayed, the environment variable is added successfully

Vi. check whether arm linux GCC is installed correctly:

arm-linux-gcc -v
Using built-in specs.
Target: arm-none-linux-gnueabi
Configured with: /opt/FriendlyARM/mini2440/build-toolschain/working/src/gcc-4.4.3/configure --build=i386-build_RedHat-linux-gnu --host=i386-build_redhat-linux-gnu --target=arm-none-linux-gnueabi --prefix=/opt/FriendlyARM/toolschain/4.4.3 --with-sysroot=/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi//sys-root --enable-languages=c,c++ --disable-multilib --with-arch=armv4t --with-cpu=arm920t --with-tune=arm920t --with-float=soft --with-pkgversion=ctng-1.6.1 --disable-sjlj-exceptions --enable-__cxa_atexit --with-gmp=/opt/FriendlyARM/toolschain/4.4.3 --with-mpfr=/opt/FriendlyARM/toolschain/4.4.3 --with-ppl=/opt/FriendlyARM/toolschain/4.4.3 --with-cloog=/opt/FriendlyARM/toolschain/4.4.3 --with-mpc=/opt/FriendlyARM/toolschain/4.4.3 --with-local-prefix=/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi//sys-root --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-c99 --enable-long-long --enable-target-optspace
Thread model: posix
gcc version 4.4.3 (ctng-1.6.1)

Shows that it has been installed successfully.

7. Write the test program and compile it with arm linux GCC:

Create an empty document, write the following code, and save it as test.c:

#include <stdio.h>

void main(void)

{

  printf("%s","Hello World!\n");

}

Enter the following command:

arm-linux-gcc -o Hello test.c

After compilation, the Hello executable will be generated. Enter the following command to view the generated file information:

readelf -h Hello
ELF Header:
  Magic:  7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                            ELF32
  Data:                              2's complement, little endian
  Version:                          1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                      0
  Type:                              EXEC (Executable file)
  Machine:                          ARM
  Version:                          0x1
  Entry point address:              0x8334
  Start of program headers:          52 (bytes into file)
  Start of section headers:          4464 (bytes into file)
  Flags:                            0x5000002, Version5 EABI, <unknown>
  Size of this header:              52 (bytes)
  Size of program headers:          32 (bytes)
  Number of program headers:        10
  Size of section headers:          40 (bytes)
  Number of section headers:        30
  Section header string table index: 27

You can see that the executable platform is ARM platform.

Tags: Linux sudo Ubuntu Unix

Posted on Tue, 03 Dec 2019 18:38:15 -0800 by piet123