Ubuntu Raspberry Pi 2b cross compiling environment, ubuntu2b

Source: Internet
Author: User

Ubuntu Raspberry Pi 2b cross compiling environment, ubuntu2b

Generate executable code on another platform. Why is cross-compilation costly? One sentence: The last thing is. Sometimes it is because the target platform does not allow or cannot install the required compiler, and some features of the compiler are required. Sometimes it is because the resources on the target platform are poor, it is impossible to run the necessary compiler. Sometimes it is because the target platform has not yet been set up, and there is no operating system. It is impossible to run any compiler.

To perform cross-compilation, We need to install the corresponding cross-compilation tool chain on the host platform, and then use this cross-compilation tool chain to compile the source code, finally, code that can be run on the target platform is generated.
Common examples of cross-compilation are as follows:

1. On Windows PC, the executable code for arm cpu can be compiled using ADS (ARM development environment) and armcc compiler.
2. Run the arm-Linux-gcc compiler on a linux PC to compile executable code for the Linux ARM platform.
3. Run the arm-elf-gcc compiler in the cygwin environment on a Windows PC to compile executable code for the arm cpu.

I. Specific terms

In Linux, most software packages use Autoconf/Automake to automatically generate Makefile. /configure "," make ", and" make install "can install the program in Linux. When compiling third-party source code, you can check the readme and install files in the project. Generally, the compilation steps are written.

1../configure common parameters [-- build] | [-- host] | [-- target] | [-- prefix] | [-- help]

Note: host and -- host do not mean either. host is the host, that is, the platform for editing and compiling programs. -- host is the host for setting the execution file to run, it is a verb.

>./Configure: used to generate the corresponding Makefile;
> -- Build: the host that executes code compilation. Normally, it is your host system. If no host value is specified;
>>-- Host: the host of the compiled binary program, and the prefix of the Cross-compilation toolchain. This value is equivalent to build because the vast majority of tasks are executed on the local machine if they are compiled. However, different values must be set for build and host during cross-compilation. Use host to specify the running host, that is, host! = Cross-compilation is performed during build. If this parameter is not specified, 'config. guess 'is run to detect the vulnerability;
> -- Prefix: installation directory. For example, -- prefix =/usr indicates to install the software under/usr, the execution file will be installed in/usr/bin (instead of the default/usr/local/bin ), the resource file will be installed in/usr/share (instead of the default/usr/local/share );
> -- Help: view parameters;
>>-- Target: this parameter is special, indicating the name of the target platform to be processed. It mainly plays a role in programming language tools such as compiler and assembler context. If no host value is specified. It is generally used as a compilation tool. For example, to compile a gcc program that can process mips for the arm Development Board, -- target = mips;
>>>> Example: Compile gcc
>./Configure -- build = i386-linux -- host = arm-linux -- target = mipsel-linux -- prefix = $ (pwd)/_ install
Using the i386-linux compiler for gcc compilation, the compiled gcc runs in arm-linux, the compilation result is stored in the $ (pwd)/_ install path, the compiled gcc is used to compile the code that can be run in mipsel-linux.

2. Makefile contains some basic pre-defined operations:

> Make: Compile the source code based on Makefile, connect to generate the target file, and execute the file;
> Make clean: Clear the object files (Files suffixed with ". o") and executable files generated by the last make command;
> Make distclean: similar to make clean, but all files generated by configure are also deleted, including Makefile;
> Make test/make check: check make to ensure that there is no error in make. It is generally executed before make install;
> Make install: install the compiled executable files to the specified directory, which is generally the/usr/local/bin directory;
> Make dist: generate the publish package file (that is, the distribution package ). This command will pack executable files and related files into a tar.gz compressed file for software release. A file named "package-version.tar.gz" will be generated in the current directory. PACKAGE and VERSION are the AM_INIT_AUTOMAKE (PACKAGE, VERSION) defined in configure. in );
> Make distcheck: Generate and test the release package to confirm the correctness of the release package. This operation will automatically unbind the compressed package file, then execute the configure command, and execute make to confirm that there is no compilation error, and finally prompt that your software package is ready and can be released;

Iii. Cross-compiling source code

1. Environment
Ubuntu

2. Install Raspberry Pi cross compiling tool

Step1. download Raspberry Pi cross compiler tool https://github.com/raspberrypi/tools
Step 2: place the source code in a folder that users can share, such as/usr/tools.
Step Add the path of the Cross-compilation tool to the environment variable. I added it to bashrc for later startup.

Step 4. Check whether the installation is successful

The following content appears:

Now the cross-compilation environment has been configured

 

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.