Use sourcery g ++ Lite to build a cross-compilation environment

Source: Internet
Author: User
[Arm note/cross-tool] Use sourcery g ++ Lite to build a cross-compilation environment

20:45:41 | category:

Arm | font size subscription

1. Get the Compiler
We can compile and create a cross-compile toolchain by ourselves. However, for convenience and stability, we usually choose a mature third-party toolchain. The cross-tool chain of codesourcery is a common one. Taking arm as an example, we can
To the latest version.
We can see that there are four OS platform versions to choose from. 1. Which one should we choose to download?

Figure 1

On a codesourcery page, we found the answer:

This table applies to the target system on which your applications will run, not to the host system on which you run sourcery g ++.

Target Platform Description
Eabi/elf RTOS systems orBare metalSystems where no operating system is present. These comprehensions shocould not be used to build linux kernels or applications.
UClinux? Systems running uClinux, I. e. Linux on CPUs without an MMU. Use sourcery g ++ to build both the uClinux kernel and applications.
GNU/Linux? Systems runningFullLinux, I. e., Linux on CPUs with an MMU. Use sourcery g ++ to build both the Linux kernel and applications.
Microsoft Windows?

Systems running Microsoft Windows 2000, or later.

That is to say, if you plan to compile Linux kernel or Linux-based applications, you should select GNU/Linux; Eabi/elf is applicable to bare metal machines without operating systems (or RTOS; uClinux is applicable to Linux without MMU.

Among them, ia32 GNU/Linux tar is the prepared compiler, and source tar is the source code. We have to download the prepared compiler and Datasheet and the user manual (Started Guide (PDF )). Note: datasheet describes the GCC and glibc versions. The user manual describes how to use them.

We download ia32 GNU/Linux tar: This is a prepared cross compiler, for example:
Arm-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2

2. Configure the Compiler
1) decompress the downloaded compressed file.
$ Tar jvxf arm-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
Generates an arm-2010.09 directory and enters the directory.
The compiler binary files are all under the/bin directory.
2) compiler parameter settings
The compiler supports three versions of CPU: armv4t, armv5t, and armv7t. The armv5t CPU is supported by default. Because my Development Board is tq2440. it belongs to the armv4t CPU. Therefore, you need to set relevant parameters during compilation. The corresponding command is: Arm-None-Linux-gnueabi-gcc-March = armv4t $ * filename
To facilitate the use of methods in the TQ manual. Create several executable scripts under the/bin directory and name them respectively: arm-Linux-xxx (xxx represents the XXX in arm-None-Linux-gnueabi-xxx in the same directory) and then add the following content to the script file:
#! /Bin/sh
Exec arm-None-Linux-gnueabi-xxx-March = armv4t $ *
Note: In fact, you only need to make executable scripts for GCC gcc-4.5.1 and G ++. For other commands, the Ln-s arm-None-Linux-gnueabi-xxx arm-Linux-xxx link points to the corresponding compiler.
This is the new arm-Linux-GCC script.
$ Cat arm-Linux-gcc
#! /Bin/sh
Exec arm-None-Linux-gnueabi-gcc-March = armv4t $ *
Then we need to understand two things:
* The path of the required cross-compiler Library (LIB) is in the directory of arm-None-Linux-gnueabi/libc/armv4t/lib, the file system we created is to use the library under this directory;
* The header file we need is in the arm-None-Linux-gnueabi/libc/usr/include/directory.
If you encounter a library required by a program in the future, you can compile it and add it to the compiler. The preliminary preparation of the cross compiler is now complete, and we can package and back up it.

Then we need to master two things:

1. The path of the Library (LIB) used by the cross compiler is: Arm-None-Linux-gnueabi/libc/armv4t/lib, the file system is created using the library in this directory;

2. the header file we need is in the arm-None-Linux-gnueabi/libc/usr/include/directory.

Then we add the libraries required for compiling QT: jpegser.v6.tar.gz, LibPNG, libz, and libuuid (e2fprogs). After these libraries are ready, copy the file to the preceding directory (including lib and include ).

If you encounter a library required by a program in the future, you can compile it and add it to the compiler. The preliminary preparation of the cross compiler is now complete, and we can package and back up it.

3) environment variable configuration

The configuration file is in the/etc/Enviroment
1.

  1. Sudo CP/etc/Enviroment
    /Etc/environmet. Old

2.

  1. Sudo Vim/etc/Enviroment
  2. Modify as follows: We added/home/ywx/ARM-cross/ARM-2010.09/bin, because we extracted the file to/home/ywx/ARM-corss.

  3. Path = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games: /home/ywx/ARM-cross/ARM-2010.09/bin :"

 

Restart the environment variable or the computer. We need to restart the computer


In this way, the self-made compiler is successfully created. Note that this compilation supports the Eabi technology, so the target kernel to be compiled must also support this technology. All kernels after Linux 2.6.16 are supported. The previous cross compiler does not support the Eabi technology.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.