In Gentoo, cross-compile SometimesitpaystostayinbedinMonday, ratherthanspendingtherestoftheweekdebuggingMonday & amp; rsquo; scode. & amp; ndash; DanSalomon took a dirty job a few days ago ,... in Gentoo, cross-compile "Sometimes it pays to stay in bed in Monday, rather than spending the rest of the week debugging Monday's code. "-Dan Salomon took a dirty job a few days ago and cross-compiled the raspbian file system image. I haven't done such a tedious task for a long time. I will write a log to share how gentoo can better solve the cross-compilation problem. The compiling environment of the embedded system www.2cto.com is used to develop software for a platform. a compiling environment is required first. Generally, the compilation environment includes three parts: tool chain, runtime environment, and compilation method. For embedded systems, there are three common compiling environments: local environments. For example, Ubuntu for ARM, which is popular, uses the official target machine image (usually including the compiling environment) to compile and install software directly on the target machine, which is exactly the same as PC development. This method is simple and easy to use. The disadvantage is that the compilation speed is slow and time-consuming, especially when large software packages (such as xbmc) are used, programmers can stop for a cup of coffee, i'm afraid I have to watch dota all night before I can see the result... (Maybe distcc can improve) the virtual environment. Create a virtual environment for the target machine on the PC, such as a QEMU-ARM, and then chroot to the virtual environment to compile/install software. This method utilizes the processing capability of the PC, which is much faster than the local environment. However, QEMU cannot simulate the target environment perfectly, for example, it does not support certain system calls, this may cause it to fail to compile some software correctly. Cross-compilation. This is the most common method and the basis for implementing the above two methods. Cross-compilation is "dirty" because it is necessary to manually solve all dependencies of the software package, compile each software package manually, and solve the compatibility of the software package to the target machine... Looking at the overwhelming online information on asking for advice/guiding how to correctly cross-compile a software package, how many programmers are being abused by it? Gentoo is a metadistribution that builds the entire system from the source code. It also supports many different body systems, such as alpha/arm/hppa/ppc/sh/iSCSI/s390, it also provides a convenient tool for cross-compilation, which is unmatched by other binary distributions (scratchbox is also weak ). Cross-compilation under gentoo is implemented through crossdev and portage. The advantage of portage is that it automatically solves dependencies and automatically upgrades and updates the system, just like the local environment. The production tool chain crossdev is used to create a cross tool chain and provides auxiliary scripts for emerge in the cross-compilation environment. For example, compile the tool chain of the arm platform: $ sudo crossdev-t arm-supertux-linux-gnueabi. in this way, crossdev finally creates an arm cross compiler that complies with the "gentoo Specification. Run crossdev to generate the/usr/arm-supertux-linux-gnueabi/directory as the target system $ buildroot. The targets generated after compilation will be emerge to $ buildroot, and the environments (such as the linked library, header file, and pkgconfig) that are dependent on during compilation will also be $ buildroot. With the tool chain/runtime environment, the emerge encapsulated by crossdev can be freely implemented. For example, cross-compiling bash: $ sudo emerge-arm-supertux-linux-gnueabi-avu bashporage will automatically execute bash dependencies such as ncurses/readline emerge together to $ buildroot. Cross-compilation is so simple... The problem we encounter can be further viewed on the shoulders of giants, provided that we need to climb the shoulders of giants first. Portage is a fast update iteration system, which is not perfect. The maintainer cannot test all compatibility of each software package. Therefore, when you want to install a graphic environment such as $ emerge-avu enlightenment, errors may occur. However, portage provides fine-grained control to help solve such problems. Below are some situations and solutions I have encountered: problems caused by the environment variables of the software package, such as the link Library pointing to/usr/bin, rather than $ buildroot. You can configure the corresponding file in the $ buldroot/etc/portage/env/Directory. portage will automatically source the file and change the compiling environment. Portage does not contain the software or portage bug. for example, it enables a feature that is not available on the target platform by default. Create an overlay for the target machine and write the ebuild file of the corresponding software package to guide the portage for cross-compilation. When a software package is compiled in stages, for example, miniperl is generated in perl compilation, and the perl target image is generated in miniperl. Because miniperl is used by the cross compiler to generate the target image, the final target image cannot be generated in the host environment normally. This requires the use of qemu-arm + binfmt to simulate the target machine environment, so that miniperl can run seamlessly in the host environment. In terms of form, it is also "dirty" to deal with the above situations ". You need to understand not only the compiling environment of the software package, but also the principles of portage and the ebuild writing syntax. However, compared with the traditional cross-compilation method, this is a permanent task. when others use my runtime environment and overlay, they can generate the final target machine system without having to do anything else. Three years ago, a gentoo + xserver + enlightenment target machine system was created using the above method and runs on the mini2440 Development Board. This method greatly reduces the compilation time and maintenance workload of more than 200 software packages in the target system.
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