Cross-Compilation of Linux Programming

Source: Internet
Author: User
Cross-Compilation of Linux programming-general Linux technology-Linux programming and kernel information. The following is a detailed description. I. Copyright description
Purpose:
The purpose of this copyright statement is to ensure that anyone can truly and effectively enjoy the full freedom to use the documents restricted by this copyright note. At the same time, the rights of the original author of this document are protected, not only do they receive the honors they deserve, but they also ensure that the original author is not responsible for the consequences caused by changes made by others.

Statement:
A. Unless otherwise stated, the copyright of the document belongs to its author. All authors of this plan reserve all rights.

B. The free documentation generated by this plan allows everyone to use it freely (including the commercial or non-commercial reproduction and redistribution of this document ), without the need to pay any fee to the OPENARM program or the author, this copyright statement is contained in all copies and the copyright statement of the Free Documentation is sacred and irrevocable, the user shall not modify any clause in any form or add any other conditions.

C. allow anyone to copy and publish a free document after it is modified in compliance with this copyright notice. If you have modified the free document or published a copy of the revised version, you will no longer be a user in the general sense and become the author of the revision, and these regulations will be turned into your responsibility. The author shall follow the following rules:

1. The revised version shall contain the copyright notice of the free document having the same content as the previous version, but with respect to the modified part, the revised version shall have its own copyright.
2. Protect the authority of the original author and the author of the earlier version. The name and contact information of the original author and the original author shall be retained in the revised version.
3. The author, revision time, contact information, publisher, and other related information of each version is recorded.
4. The author has the obligation to tell readers how to obtain the document of the previous version. If the document is published on the website, a link should be made to the position of the document of the previous version.

D. Anyone can reference part of this document or mix part of this document with other documents, provided that this copyright notice must be added to the referenced document. The above actions can be handled in accordance with item c

E. translation. If it is necessary to translate the document in this plan into other languages, such behavior will be considered as a re-Revision of the revised version, which may be handled in accordance with item c.

F. The original author shall not, under any circumstances, bear any direct, indirect, or special consequences to any party arising from the use of this document, attached or accompanied damages, including the liability for loss of interest, even if the original author has suggested the possibility of such losses in the document.





Ii. What is cross-compilation?
What is cross-compilation? In short, it is to generate executable code on one platform. The so-called platform actually contains two concepts: Architecture and Operating System ). The same individual structure can run different operating systems. Likewise, the same operating system can run on different architectures. For example, we often say that the x86 Linux platform is actually a general term of the Intel x86 architecture and the Linux for x86 operating system; the x86 WinNT platform is actually an Intel x86 architecture and Windows NT for x86 operating system.

A frequently asked question is, "since we already have a host compiler, why do we need to perform cross-compilation ?" In fact, the answer is very simple, no way! Sometimes it is because the target platform does not allow or cannot install the compiler we need, and we need some features of this compiler; sometimes it is because the resources on the target platform are poor, we cannot run the compiler we need. Sometimes it is because the target platform has not yet been set up, and even the operating system does not have any compiler.

Another frequently asked question is: "Since cross-compilation is supported, what should I do with host compilation ?" In fact, the answer is also very simple, and cross-cutting translation is a last resort! Compared with host compilation, cross-compilation is more restricted. Although we can perform any form of cross-compilation in theory, in fact, due to the limitations of patents, copyrights, and technologies, it is not always possible to perform cross-compilation, especially in your spare time! For example, we have not yet been able to generate proprietary som-format executable files for Hewlett-Packard, so we simply cannot do cross-Compilation of the Target Platform for HPPA-HPUX.

For our project, there are two reasons for cross-Compilation: first, in the initial stage of the project, the target platform has not yet been established, so cross-compilation is required, to generate the required bootloader (boot guide Code) and the core of the operating system. Secondly, when the target platform can be started, due to resource restrictions on the target platform, when compiling large programs, we may still need to use cross-compilation.



III. Basic knowledge of cross-Compilation
Before doing practical work, I think we should first master some basic knowledge about cross-compilation. In fact, to put it bluntly, we should understand some frequently encountered English words ;)

Host platform.
Target platform.
The installation location of the perfix cross compiler.
Platform description of xxx-xxxx-xxxxx.

We develop programs on the host platform and run the cross compiler on this platform to compile our programs. Programs generated by the cross compiler will run on the target platform. Here it is worth noting that the platform description, such as arm-linux, i386-pc-linux2.4.3 string we often see, in fact it is used to describe the platform, it has the complete format, the reduced format, and the alias. The complete format is: CPU-manufacturer-operating system, such as sparc-sun-sunos4.1.4, indicating that the platform uses the CPU is, the version is 4.1.4. Of course, we do not want to remember such long things, so we can use short formats. The short formats selectively include information such as the manufacturer and software version, so we can also describe the platform with either the iscsi-sunos or the sparc-sunos-sunos4. If you think this is too troublesome, you can use an alias. sun4m can easily describe this platform. Note that not all platforms have aliases, and not all short formats can correctly describe the platform.



4. What should I prepare?
First, you have to prepare the host platform. For our project, we recommend that you use x86 Linux as the host platform, because this requires the least setup work. Of course, you can also use your favorite platform or the platform you can obtain. The difference is that you may have to do more settings, and of course, this is also possible, that is, the host platform you selected cannot generate a correct cross compiler for the target platform.

Cross-compiler can be generated by yourself or downloaded from the Internet. The difference is that download from the Internet is very simple and convenient, but you may not find a suitable platform for your choice. The self-generated cross-compiler sometimes encounters many setbacks, but this is indeed an interesting and memorable experience.

If you want to generate a cross compiler, you must first prepare the following:

1. disk space. It takes at least MB of space. If you want to achieve it in one breath, you need a-1 GB space.
2. Various source code. You must at least prepare the source code for the binutils-2.11.2, gcc-2.95.3, linux-2.4.6, newlib-1.8.2, or glibc-2.2.2.

If your host platform is not running linux, you must pay attention to the following issues:

1. GNU bash must be the default shell, so you may have to change/bin/sh to bash.
2. Check that GNU bison has been installed, because these softwares also use the bison extension.
3. It is best to use the default make command for the GNU gmake system, because these software uses the gmake extension. If not, remember
Use gmake.
4. If you want to generate a cross glibc, GNU gsed must be the default sed, because glibc will use the gsed extension.
5. If you want to generate a cross glibc, you must also prepare the source code of the glibc-linuxthreads-2.2.2.
6. Confirm the correct path search order and make sure that the GNU software is executed first.



5. How to generate a Cross Compiler
We recommend that you use a ready-made script to generate a cross-compiler, because some incomprehensible switch items are often used when you configure the cross-compiler.

To be continued ......



Vi. References
Http://www.objsw.com/CrossGCC/ is an old-fashioned cross-compilation FAQ, unfortunately it has been rarely updated recently.
Http://crossgcc.billgatliff.com/This is a new generation of cross-compilation FAQ, currently updated more frequently.
Mail list for the crossgcc@sourceware.cygnus.com cross compiler.
Related Article

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.