A method for cross - architecture compilation under Linux
By streamlining the Linux Arm64 system and installing the compilation tool chain, the device limitations of cross-architecture compilation under the Linux system are solved, efficient cross-architecture compilation is achieved, reducing costs and improving development efficiency.
Patent Information
- Application Number
- CN202210676332.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-15
- Publication Date
- 2025-07-25
- Estimated Expiration
- 2042-06-15
AI Technical Summary
The existing technology cannot realize cross-platform cross-architecture compilation from Intel X86 architecture to Arm64 architecture under Linux systems, resulting in developers needing to purchase specific devices for code debugging, which increases the cost of equipment procurement and development difficulty.
By streamlining the Linux Arm64 system, configuring environment variables, and installing a compilation toolchain for Linux Arm64, including compilers, linkers and debuggers, the toolchain is used to connect dependent software libraries to achieve cross-architecture compilation.
It reduces equipment procurement costs, improves development efficiency, realizes efficient cross-architecture compilation under different architectures, and reduces dependence on high-configuration Arm64 hosts.
Smart Images

Figure CN114995826B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a compilation method, and more specifically to a cross-architecture compilation method under Linux. Background Art
[0002] With the release of Apple's M1 chip, the entire market has gradually realized that in addition to the Intel X86 architecture, there is another excellent architecture, namely Arm64, which can be applied to various fields. And our conventional technology for compilation under X86 will be subverted on Arm64 because Arm64 has its own unique CPU instruction set and is incompatible with the X86 system. So far, the implementation principles of existing cross-architecture compilation solutions on the market are all to install a cross-architecture library on the compiler of a specific programming language within a Windows system of a specific architecture. This library is provided in a pre-compiled manner and provides the ability to translate specific CPU instruction sets, ultimately achieving cross-architecture compilation. However, within the Linux system, since the system itself is tightly bound to the architecture during compilation and construction, it does not have the ability to directly perform cross-architecture compilation.
[0003] This is also reflected in Apple's M1. If a developer attempts to develop an application and wants to allow it to be used on M1, then they must purchase an M1 computer, otherwise such development cannot be carried out. That is to say, under the Intel X86 system, it is impossible to directly cross-architecture compile to Arm64.
[0004] Currently, the cross-architecture compilation method in the existing technology mainly uses the above-mentioned pre-compiled library and cooperates with a specified toolchain to achieve cross-architecture compilation. However, it only allows cross-architecture compilation of Arm64 Windows under Windows, or cross-platform compilation of X86 Linux, but it is impossible to achieve cross-platform and cross-architecture compilation from Windows X86 to Linux Arm64. Summary of the Invention
[0005] Aiming at the deficiencies of the existing technology, the purpose of the present invention is to provide a method for compiling a program from one architecture to another in a Linux environment. It solves the drawbacks that originally required purchasing specific equipment and debugging code on the equipment during cross-architecture compilation, enhances the productivity of development and compilation under different architectures, and reduces equipment requirements and procurement costs.
[0006] To achieve the above purpose, the present invention provides the following technical solution: A cross-architecture compilation method under Linux, including the following steps:
[0007] Step 1, streamline the Linux Arm64 system;
[0008] Step 2: Configure environment variables;
[0009] Step 3: Install the compilation toolchain for LinuxArm64 and connect the dependent software library through the toolchain.
[0010] As a further improvement of the present invention, the specific steps of streamlining the Linux Arm64 system in step 1 are as follows:
[0011] Step one, trim the standard Arm64 version of Linux, remove hardware-related drivers, remove background services, and remove applications other than the kernel and standard libraries to complete the steps of streamlining the Linux Arm64 system.
[0012] As a further improvement of the present invention, the trimming step in step 1 is specifically as follows: after installing the Linux system, unnecessary files in the system are deleted, unnecessary services are stopped and their executable files are deleted, service descriptions are deleted, and drivers are deleted, so as to finally obtain a streamlined system that cannot be started on a physical device but can be started in a virtual machine environment without any additional files;
[0013] Among them, the streamlined system can generate an image through the Linux built-in dd command and copy it to other systems for use.
[0014] As a further improvement of the present invention, the steps of configuring the environment variables in step 2 are as follows:
[0015] Step 21, after confirming the better root, enter the specified user directory;
[0016] Step 22: In the / root directory, write the corresponding sh configuration file;
[0017] Step 2 and 3: Add a new / root / .bashrc file to configure the environment;
[0018] Step 24: After the environment configuration is completed, copy the relevant files to the system.
[0019] As a further improvement of the present invention, the compilation tool chain installed in step 3 includes:
[0020] Compiler, used to provide software compilation;
[0021] Linker, used to implement software linking;
[0022] Debugger, used to provide software debugging.
[0023] As a further improvement of the present invention, after streamlining the Linux Arm64 system in step one, the files in the original system are also mounted.
[0024] The beneficial effects of the present invention are as follows. Through the settings of steps one to three, the installation of the corresponding compilation toolchain can be achieved by using a streamlined system. In this way, developers can use the compilation toolchain to perform cross-architecture program compilation, greatly reducing the compilation cost and improving work efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] Figure 1 It is a schematic flowchart of the method for cross-architecture compilation under Linux of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0026] The present invention will be further described in detail below with reference to the embodiments given in the drawings.
[0027] Refer to Figure 1 As shown, a method for cross-architecture compilation under Linux in this embodiment includes the following steps:
[0028] Step one, streamline the Linux Arm64 system;
[0029] Step two, configure the environment variables;
[0030] Step three, install the compilation toolchain applicable to LinuxArm64, and connect to the dependent software libraries through the toolchain. During the process of using the method of this embodiment, only need to execute steps one to three in sequence. In this way, a system installed with the compilation toolchain can be effectively formed, so that developers can effectively perform software compilation, greatly increasing work efficiency, and there is no need to specifically purchase a high-configured Arm64 host for specific compilation work.
[0031] As a specific implementation of the improvement, the specific steps of streamlining the Linux Arm64 system in step one are as follows:
[0032] Step 1: trimming on the standard Arm64 version of Linux, removing hardware-related drivers, background services, and applications other than the kernel and standard libraries, and the streamlining steps of the Linux Arm64 system can be completed. By setting the above steps, the streamlining operation can be effectively achieved. The so-called streamlined cross-architecture Linux system refers to trimming on the standard Arm64 version of Linux, removing hardware-related drivers, background services, and applications other than the kernel and standard libraries. Therefore, the streamlined Linux system has nothing to do with the hardware system. It is just a pure software system that can be placed in any Linux environment and run by changing the root directory.
[0033] As a specific implementation method of the improvement, the trimming step in the step one is specifically as follows: after installing the Linux system, unnecessary files in the system are deleted, unnecessary services are stopped and their executable files are deleted, service descriptions are deleted, and drivers are deleted, so as to finally obtain a streamlined system that cannot be started on a physical device but can be started in a virtual machine environment without any additional files;
[0034] Among them, the streamlined system can generate an image through the dd command that comes with Linux, and copy it to other systems for use. Through the above settings, the trimming steps can be effectively implemented. For a standard Linux system, only the kernel is needed to complete the startup, so other components are not necessary. After installing the Linux system, delete unnecessary files in the system, stop unnecessary services and delete their executable files, delete service descriptions, and delete drivers. Finally, you will get a streamlined system that cannot be started on a physical device but can be started in a virtual machine environment without any additional files. This system can be generated through the dd command that comes with Linux, and copied to other systems for use.
[0035] As an improved specific implementation method, the steps of configuring the environment variables in step 2 are as follows:
[0036] Step 21, after confirming the better root, enter the specified user directory;
[0037] Step 22: In the / root directory, write the corresponding sh configuration file;
[0038] Step 2 and 3: Add a new / root / .bashrc file to configure the environment;
[0039] Step 24: After the environment configuration is completed, copy the relevant files into the system. During the process of streamlining Linux, since the system startup process is removed, there are no environment variables after changing the Root. Therefore, the content related to the environment needs to be added manually. For example, the default bin / sbin location of the system and the location of the / usr directory. First, determine the user directory to be specified after changing the root. The user directory refers to the working directory belonging to the user, and this directory is usually / root. Therefore, in the / root directory, write the corresponding sh configuration file. When using Ubuntu as the distribution for streamlining, the sh used is bash, and the newly added / root / .bashrc file is used for environment configuration. When using Alpine as the distribution for streamlining, the sh used is ash, that is, the / root / .ash file needs to be newly added for environment configuration. After the environment configuration is completed, the relevant files need to be manually copied into the system. For example, if the streamlined system is to be used for Go language compilation, the Go language-related compilers and library files need to be copied in. After completion, the Linux-built dd command also needs to be used to generate the image.
[0040] As a specific implementation of the improvement, the compilation toolchain installed in Step 3 includes:
[0041] A compiler for providing software compilation;
[0042] A linker for realizing software linking;
[0043] A debugger for providing software debugging. Through the settings of the above steps, the installation of the compilation toolchain can be effectively realized, which is equivalent to installing the corresponding development tools on an Arm64 device. During the installation process, if it is not desired to have the streamlined system connected to the network, the dependent software libraries can be installed simultaneously to provide the necessary files during linking; if the streamlined system can be connected to the network, the dependent code can be pulled according to the normal development process, and the dependencies can be compiled and linked into an executable program.
[0044] As a specific implementation of the improvement, after streamlining the Linux Arm64 system in Step 1, the files in the original system are also mounted. In the streamlined system, since changing the Root directory brings the problem of non-interoperability with the original system file system, it is necessary to mount the files in the original system additionally so that they can be recognized in the streamlined system, and when modifying files in the streamlined system, they can be directly synchronized to the original system.
[0045] In summary, through the settings in steps 1 to 3, a system installed with a compilation toolchain can be effectively constructed, and this system can be placed in any Linux environment and run by changing the Root directory. In this way, there is no need to specifically purchase a high-configured Arm64 host for specific compilation work, effectively reducing the development cost and increasing the compilation efficiency.
[0046] The above description is only the preferred embodiment of the present invention, and the protection scope of the present invention is not limited to the above embodiments. All technical solutions within the idea of the present invention belong to the protection scope of the present invention. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present invention, several improvements and refinements should also be regarded as the protection scope of the present invention.
Claims
1. A method for cross - architecture compilation under Linux, characterized in that: The steps include: Step 1: Streamline the Linux Arm64 system. The specific steps are as follows: Step 1: Trim on the standard Arm64 version of Linux: After installing the Linux system, delete unnecessary files in the system, stop unnecessary services and delete their executable files, delete service descriptions, delete drivers, and finally get a streamlined system that cannot be started on a physical device but can be started in a virtual machine environment without any additional files; the streamlined system can generate an image through the dd command that comes with Linux, and copy it to other systems for use; remove hardware-related drivers, background services, and applications other than the kernel and standard libraries to complete the streamlining steps for the Linux Arm64 system; the streamlined Linux system has nothing to do with the hardware system, it is only a pure software system, which can be placed in any Linux environment and run by changing the root directory; Step 2, configure environment variables, the steps are as follows: Step 21, after determining the better root, enter the specified user directory; Step 22, in the / root directory, write the corresponding sh configuration file; Step 23, add the / root / .bashrc file to configure the environment; Step 24, after the environment configuration is completed, copy the relevant files to the system: In the process of streamlining Linux, since the system startup process is removed, there are no environment variables after changing the root, so the content related to the environment needs to be added manually. First, after determining that the root is changed, the specified user directory needs to be specified. The user directory refers to the user's working directory, which is usually / root. In the / root directory, write the corresponding sh configuration file. When Ubuntu is used as the distribution for streamlining, the sh used is bash, and the / root / .bashrc file is added to configure the environment. When Alpine is used as the distribution for streamlining, the sh used is ash, that is, the / root / .ash file needs to be added to configure the environment; after the environment configuration is completed, the relevant files need to be manually copied to the system. The streamlined system will be used for go language compilation, so go needs to be added. Copy the language-related compiler and library files into the system. After completion, you also need to use the Linux built-in dd command to generate the image. Step three: Install the compilation tool chain for LinuxArm64 and connect the dependent software library through the tool chain.
2. The method for cross-architecture compilation under Linux according to claim 1, wherein: The compilation tool chain installed in step 3 includes: Compiler, used to provide software compilation; Linker, used to implement software linking; Debugger, used to provide software debugging.
3. The method for cross-architecture compilation under Linux according to claim 1, wherein: In the step 1, after streamlining the Linux Arm64 system, the files in the original system are also mounted.
Citation Information
Patent Citations
Operating system building method and system
CN114115923A