Cross-compilation tool chain construction method, device, electronic device and storage medium
By building a cross-compilation tool chain for each target platform, the problem that the existing tool chain cannot meet the needs of multiple platforms is solved, flexibility and maintenance is improved, and cross-compilation work of multiple platform architectures is supported.
Patent Information
- Application Number
- CN202010599357.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-06-28
- Publication Date
- 2025-02-25
- Estimated Expiration
- 2040-06-28
Smart Images

Figure CN113849181B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method, device, electronic device and storage medium for constructing a cross-compilation tool chain. Background Art
[0002] Running a compiler in one computer environment to compile computer target code into a program that can run in another computer environment is called cross-compilation, and the compiler used is the cross-compilation tool chain.
[0003] The main reasons for cross-compilation at present are as follows:
[0004] ①Speed: The target platform often runs much slower than the host. Many dedicated embedded hardware are designed to be low-cost and low-power without very high performance.
[0005] ②Capability: The entire compilation process is very resource-intensive, and embedded systems often do not have enough memory or disk space.
[0006] ③Availability: Even if the target platform has sufficient resources and can be compiled locally, the first local compiler running on the target platform always needs to be obtained through cross-compilation.
[0007] ④Flexibility: A complete Linux compilation environment requires many support packages. Cross-compilation eliminates the need to spend time porting various support packages to the target board.
[0008] It should be noted that the necessary tool for cross-compilation is the cross-compilation tool chain. Currently, some cross-compilation tool chains compiled for specific CPU platforms can be obtained on the Internet, such as a cross-compilation tool chain specifically for the mips platform and a cross-compilation tool chain specifically for the x86 platform. However, these cross-compilation tool chains obtained from the Internet have the following problems:
[0009] 1. There is only a cross-toolchain for a specific platform, so it cannot meet the actual project needs; 2. Its compilation effects are unclear, it cannot be upgraded at any time, and it is difficult to add patches. Summary of the invention
[0010] In view of the problems in the prior art, embodiments of the present invention provide a method, device, electronic device and storage medium for constructing a cross-compilation tool chain.
[0011] Specifically, the embodiment of the present invention provides the following technical solutions:
[0012] In a first aspect, an embodiment of the present invention provides a method for constructing a cross-compilation tool chain, comprising:
[0013] Create file directories for each target platform;
[0014] Obtain the source code and third-party library files of the cross-compilation tools applicable to each target platform;
[0015] Get the system core files applicable to each target platform;
[0016] According to the source code and third-party library files of the cross-compilation tools applicable to each target platform, compile and install the cross-compilation tools applicable to the corresponding target platform into the file directory of the corresponding target platform, and store the obtained system core files applicable to the corresponding target platform into the file directory of the corresponding target platform to build a cross-compilation tool chain applicable to each target platform.
[0017] Furthermore, the file directory of each target platform includes a tool folder, an installation directory folder, and a system core file folder;
[0018] The tool folder is used to store the source code of the cross-compilation tool suitable for the corresponding target platform and the third-party library files;
[0019] The installation directory folder is used to store the installation files after the source code in the tool folder is compiled and the installation files of the third-party library files;
[0020] The system core file folder is used to store system core files applicable to the corresponding target platform.
[0021] Furthermore, the cross-compilation tool includes: gcc and binutils;
[0022] Accordingly, obtain the source code and third-party library files of the cross-compilation tools applicable to each target platform, including:
[0023] Determine the gcc source code and third-party library files applicable to each target platform;
[0024] Determine the binutils source code and third-party library files applicable to each target platform.
[0025] Further, according to the source code and third-party library files of the cross-compilation tools applicable to each target platform, the cross-compilation tools applicable to the corresponding target platform are compiled and installed into the file directory of the corresponding target platform, including:
[0026] According to the gcc source code and third-party library files applicable to each target platform, compile gcc and install it to the file directory of the corresponding target platform;
[0027] According to the binutils source code and third-party library files applicable to each target platform, compile binutils and install it to the file directory of the corresponding target platform.
[0028] Furthermore, according to the source code and third-party library files of gcc applicable to each target platform, gcc is compiled and installed into the file directory of the corresponding target platform, including:
[0029] Determine the value of the gcc installation parameter --prefix--target applicable to each target platform;
[0030] According to the third-party library files and the values of the installation parameters --prefix--target, compile gcc and install it to the file directory of the corresponding target platform;
[0031] Accordingly, according to the binutils source code and third-party library files applicable to each target platform, compile and install binutils into the file directory of the corresponding target platform, including:
[0032] Determine the value of the binutils installation parameter --prefix--target applicable to each target platform;
[0033] Compile and install binutils to the file directory of the corresponding target platform according to the third-party library files and the values of the installation parameters --prefix--target.
[0034] Furthermore, when gcc is compiled and installed to the file directory of the corresponding target platform according to the third-party library file and the value of the installation parameter --prefix--target, it is determined whether to add -enable-languages=c,c++ according to whether c and c++ functions are needed.
[0035] Further, the system core files include one or more of lib, lib64, lib32, / usr / include, / usr / lib, / usr / lib32, / usr / lib64 and / usr / libexec;
[0036] Accordingly, the obtained system core files suitable for the corresponding target platform are stored in the file directory of the corresponding target platform, including:
[0037] Package and copy the system core files suitable for the corresponding target platform and unzip them to the file directory of the corresponding target platform to ensure the soft link properties of the system core files.
[0038] Among them, when the file linked by the soft link of the system core file has the same access path as the file on the host machine where the target platform is located, the soft link attribute of the system core file is modified so that the file linked by the soft link of the system core file no longer has the same access path as the file on the host machine where the target platform is located.
[0039] Furthermore, the cross-compilation tool chain construction method further includes:
[0040] When the ld script is recorded in libc.so of the target code to be cross-compiled to the corresponding target platform, the libc path that ld.so depends on, which is specified by the ld script, is modified to a path applicable to the target platform;
[0041] When the ld script is recorded in libpthread.so of the target code to be cross-compiled to the corresponding target platform, the libpthread path that ld.so depends on and specified by the ld script is modified to a path applicable to the target platform.
[0042] Furthermore, the cross-compilation tool chain construction method further includes:
[0043] According to the system core files stored in the file directory of the corresponding target platform and the compiled and installed cross-compilation tools, the target code to be cross-compiled to the corresponding target platform is cross-compiled into a code suitable for the corresponding target platform.
[0044] In a second aspect, an embodiment of the present invention further provides a cross-compilation tool chain construction device, comprising:
[0045] Create a module to create file directories for each target platform;
[0046] The first acquisition module is used to acquire the source code and third-party library files of the cross-compilation tool applicable to each target platform;
[0047] The second acquisition module is used to acquire system core files applicable to each target platform;
[0048] The construction module is used to compile and install the cross-compilation tools suitable for the corresponding target platforms into the file directory of the corresponding target platforms according to the source code and third-party library files of the cross-compilation tools applicable to the corresponding target platforms, and store the obtained system core files suitable for the corresponding target platforms into the file directory of the corresponding target platforms to build a cross-compilation tool chain suitable for each target platform.
[0049] In a third aspect, an embodiment of the present invention further provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the cross-compilation tool chain construction method described in the first aspect are implemented.
[0050] In a fourth aspect, an embodiment of the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the cross-compilation tool chain construction method as described in the first aspect.
[0051] In a fifth aspect, an embodiment of the present invention further provides a computer program product, the computer program product comprising a computer program, which, when executed by a processor, implements the steps of the cross-compilation tool chain construction method as described in the first aspect.
[0052] It can be seen from the above technical scheme that the cross-compilation tool chain construction method, device, electronic device and storage medium provided in the embodiments of the present invention create a file directory for each target platform, compile and install the cross-compilation tool suitable for the corresponding target platform into the file directory of the corresponding target platform, and store the obtained system core files suitable for the corresponding target platform into the file directory of the corresponding target platform to build a cross-compilation tool chain suitable for each target platform. It can be seen that the embodiments of the present invention propose a universal cross-compilation tool chain construction method, which can customize a cross-compilation tool chain that meets the actual needs of the project, for example, it can support cross-compilation of various platform architectures such as arm, mips, x86, alpha, etc., and no longer rely on cross-compilation tool chains that do not meet the actual project needs, such as unknown special effects on the network, inability to upgrade at any time, difficulty in appending patches, etc. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0054] Figure 1 A flowchart of a method for constructing a cross-compilation tool chain provided by an embodiment of the present invention;
[0055] Figure 2 A schematic diagram of the structure of a cross-compilation tool chain construction device provided by an embodiment of the present invention;
[0056] Figure 3 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0057] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0058] Run a compiler in a computer environment, and compile the computer object code into a program that can be run in another computer environment. This compilation process is cross-compilation, and the compiler used is a cross-compilation tool chain. It can be seen that the necessary tool for cross-compilation is the cross-compilation tool chain. At present, some cross-compilation tool chains compiled for specific CPU platforms can be obtained on the Internet. When the cross-compilation tool chain cannot meet the actual project requirements, building a universal cross-compilation tool chain becomes a necessary task. In view of this situation, the present invention proposes a universal cross-compilation tool chain construction method, which can customize a cross-compilation tool chain that meets the actual needs of the project to support cross-compilation work of different platform architectures such as arm, mips, x86, alpha, etc., and no longer rely on unknown special effects on the network, cannot be upgraded at any time, and is difficult to add patches, etc., which do not meet the actual project requirements. The cross-compilation tool chain construction method provided by the present invention will be explained and described in detail below through specific embodiments.
[0059] Figure 1 FIG. 1 is a flow chart showing a method for constructing a cross-compilation tool chain according to an embodiment of the present invention. Figure 1 As shown, the cross-compilation tool chain construction method provided by the embodiment of the present invention includes the following steps:
[0060] Step 101: Create a file directory for each target platform;
[0061] In this step, you can create a / root / cross_compilation directory to manage the cross-compilation tool chains of all target platforms, and then create file directories corresponding to each target platform under the / root / cross_compilation directory. For example, you can create file directories corresponding to each target platform (such as arm, mips, x86, alpha): arm folder, mips folder, x86 folder, alpha folder, which are used to store the source code and third-party library files of the cross-compilation tools applicable to the corresponding target platforms.
[0062] For example, under / root / cross_compilation, create a file directory corresponding to the arm platform: / root / cross-compilation / arm. Furthermore, under the arm folder, you can further create various files in sequence to store the source code of the cross-compilation tool applicable to the arm platform and third-party library files and other files.
[0063] Step 102: Obtain source code and third-party library files of cross-compilation tools applicable to each target platform;
[0064] In this step, the cross-compilation tools may include gcc and binutils, so you can check the gcc version and binary tool binutils (ld|nm|strip, etc.) version applicable to each target platform, and then find the corresponding source code package download (http: / / ftp.gnu.org / gnu / gcc, http: / / ftp.gnu.org / gnu / binutils). In addition, after downloading gcc and binutils applicable to each target platform, you need to install the downloaded cross-compilation tools gcc and binutils applicable to each target platform to the file directory of the corresponding target platform respectively.
[0065] Step 103: Obtain system core files applicable to each target platform;
[0066] In this step, since the system core file of the target platform is needed when cross-compiling, it is necessary to first obtain the system core file applicable to each target platform.
[0067] Step 104: According to the source code and third-party library files of the cross-compilation tools applicable to each target platform, compile and install the cross-compilation tools applicable to the corresponding target platform into the file directory of the corresponding target platform, and store the obtained system core files applicable to the corresponding target platform into the file directory of the corresponding target platform to build a cross-compilation tool chain applicable to each target platform.
[0068] In this step, after obtaining the source code and third-party library files of the cross-compilation tools applicable to each target platform and the system core files applicable to each target platform, the cross-compilation tools applicable to the corresponding target platform are compiled and installed into the file directory of the corresponding target platform, and the obtained system core files applicable to the corresponding target platform are stored in the file directory of the corresponding target platform to build a cross-compilation tool chain applicable to each target platform.
[0069] It can be seen from the above technical scheme that the cross-compilation tool chain construction method provided in this embodiment creates a file directory for each target platform, compiles and installs the cross-compilation tool suitable for the corresponding target platform into the file directory of the corresponding target platform, and stores the obtained system core files suitable for the corresponding target platform into the file directory of the corresponding target platform to construct a cross-compilation tool chain suitable for each target platform. It can be seen that the embodiment of the present invention proposes a universal cross-compilation tool chain construction method, which can customize a cross-compilation tool chain that meets the actual needs of the project, for example, it can support cross-compilation of various platform architectures such as arm, mips, x86, alpha, etc., and no longer relies on cross-compilation tool chains that do not meet the actual project needs, such as unknown special effects on the network, inability to upgrade at any time, difficulty in appending patches, etc.
[0070] Based on the content of the above embodiment, in this embodiment, the file directory of each target platform includes a tool folder, an installation directory folder and a system core file folder;
[0071] The tool folder is used to store the source code of the cross-compilation tool suitable for the corresponding target platform and the third-party library files;
[0072] The installation directory folder is used to store the installation files after the source code in the tool folder is compiled and the installation files of the third-party library files;
[0073] The system core file folder is used to store system core files applicable to the corresponding target platform.
[0074] In this embodiment, an installation directory is created to facilitate later cross-compilation path management:
[0075] S1. Create the / root / cross_compilation directory to manage cross compilation for all target platforms.
[0076] S2. Under this directory, create a file directory for each platform. For example, for the arm platform, create a corresponding folder: / root / cross-compilation / arm.
[0077] S3. Under this folder, create: cross|tools|sysroot|work_src in sequence, where the tools folder stores the source code of the cross-compilation tool and third-party library files suitable for the corresponding target platform; the cross folder stores the installation files after the source code in the tools folder is compiled and the installation files of the third-party library files; sysroot stores the system core files suitable for the corresponding target platform; work_src stores the code to be cross-compiled.
[0078] In the present embodiment, corresponding file directories are created for different target platforms, respectively, so that it is convenient to manage the cross-compilation tool chains belonging to different target platforms. In addition, at least four folders cross|tools|sysroot|work_src are further subdivided under the file directory corresponding to each target platform, which are used to store the source code and third-party library files of the cross-compilation tool applicable to the corresponding target platform, the installation files after the source code in the tools folder is compiled and the installation files of the third-party library files, the system core files applicable to the corresponding target platform, and the codes to be cross-compiled, so that the files required for cross-compilation are stored in different folders, respectively, so that the management of the cross-compilation process is facilitated, so that cross-compilation can be smoothly implemented and abnormalities in the cross-compilation process can be avoided.
[0079] Based on the content of the above embodiment, in this embodiment, the cross-compilation tool includes: gcc and binutils;
[0080] Accordingly, obtain the source code and third-party library files of the cross-compilation tools applicable to each target platform, including:
[0081] Determine the gcc source code and third-party library files applicable to each target platform;
[0082] Determine the binutils source code and third-party library files applicable to each target platform.
[0083] In the present embodiment, it should be noted that gcc (gnu collect compiler) is a general term for a group of compiler tools. The main tasks it completes are preprocessing and compilation, and the support of the runtime library closely related to the compiler is provided, such as libgcc_s.so, libstdc++.so, etc. Binutils provides a series of tool programs for creating, managing and maintaining binary target files, such as assembling (as), connecting (ld), static library archiving (ar), disassembling (objdump), elf structure analysis tool (readelf), invalid debugging information and symbolic tool (strip), etc. In general, binutils is closely integrated with gcc, and without binutils, gcc generally cannot work normally. Therefore, in the present embodiment, it is necessary to download and compile the cross-compilation tool gcc and binutils applicable to the corresponding target platform and install them in the file directory of the corresponding target platform.
[0084] In this embodiment, the cross-compilation tools gcc and binutils suitable for the corresponding target platform are compiled and installed into the file directory of the corresponding target platform to ensure the smooth progress of the cross-compilation work.
[0085] Based on the content of the above embodiment, in this embodiment, according to the source code and third-party library files of the cross-compilation tools applicable to each target platform, the cross-compilation tools applicable to the corresponding target platform are compiled and installed into the file directory of the corresponding target platform, including:
[0086] According to the gcc source code and third-party library files applicable to each target platform, compile gcc and install it to the file directory of the corresponding target platform;
[0087] According to the binutils source code and third-party library files applicable to each target platform, compile binutils and install it to the file directory of the corresponding target platform.
[0088] In this embodiment, before installation, you can first view the help document through . / configure --help to see the precautions and parameters. The installation parameters only need to use --prefix --arget, where target is determined according to the target platform to be cross-compiled. The currently used ones are: mipsel-linux|mips64el-linux|aarch64-linux, such as:
[0089] ①. / configure--prefix= / root / cross-compilation / mipsel64 / cross / --target=mips64el-linux&&make&&make install
[0090] ②. / configure--prefix= / root / cross-compilation / mipsel / cross / --target=mipsel-linux&&make&&make install
[0091] ③. / configure--prefix= / root / cross-compilation / aarch64 / cross / --target=aarch64-linux&&make&&make install.
[0092] In this embodiment, a specific process of compiling and installing the cross-compilation tool binutils into the file directory of the corresponding target platform is given. Through this embodiment, the cross-compilation tool binutils can be successfully installed into the file directory of the corresponding target platform, and at the same time, it is ensured that the installed binutils can provide tool support for the cross-compilation process.
[0093] Based on the content of the above embodiment, in this embodiment, according to the source code and third-party library files of gcc applicable to each target platform, gcc is compiled and installed to the file directory of the corresponding target platform, including:
[0094] Determine the value of the gcc installation parameter --prefix--target applicable to each target platform;
[0095] According to the third-party library files and the values of the installation parameters --prefix--target, compile gcc and install it to the file directory of the corresponding target platform;
[0096] Accordingly, according to the binutils source code and third-party library files applicable to each target platform, compile and install binutils into the file directory of the corresponding target platform, including:
[0097] Determine the value of the binutils installation parameter --prefix--target applicable to each target platform;
[0098] Compile and install binutils to the file directory of the corresponding target platform according to the third-party library files and the values of the installation parameters --prefix--target.
[0099] In this embodiment, the third-party library files (also called dependent libraries) of the cross-compilation tool gcc are installed, including:
[0100] Copy contrib / download_prerequisites in the decompressed file directory of the cross-compilation tool gcc for the corresponding target platform to the parent directory and execute it to download, decompress and softlink the gcc dependency library;
[0101] or,
[0102] If the cross-compilation tool gcc version for the target platform does not have a download_prerequisites file and does not support automatic installation of dependent libraries, manually download and install the dependent libraries, and add parameters to specify the installation path of the dependent libraries when installing gcc.
[0103] In this embodiment, for some old versions of gcc, since they do not have a download_prerequisites file and do not support automatic installation of dependent libraries, these dependent libraries such as mpc need to be downloaded and installed manually. The installation order is: gmp, mpfr, mpc, isl, cloog, and when installing gcc, you need to add parameters to specify the installation path of the dependent library, as shown below:
[0104] . / configure--prefix= / root / cross_compilation / aarch64 / cross\
[0105] --target=aarch64-linux\
[0106] --with-gmp= / root / cross_compilation / aarch64 / cross\
[0107] --with-mpfr= / root / cross_compilation / aarch64 / cross\
[0108] --with-mpc= / root / cross_compilation / aarch64 / cross\
[0109] --with-isl= / root / cross_compilation / aarch64 / cross\
[0110] --with-cloog= / root / cross_compilation / aarch64 / cross\
[0111] --enable-languages=c,c++\
[0112] --disable-multilib&&make all-gcc&&make install-gcc
[0113] You may encounter various problems during the installation of binutils and gcc. For specific problems, please refer to files such as config.log and analyze them according to the type of problem.
[0114] It can be seen that in this embodiment, for some lower versions of gcc, it is necessary to manually download and install dependent libraries to ensure that the installed gcc can provide normal tool support for the cross-compilation process.
[0115] In addition, in this embodiment, before installing the cross-compilation tool gcc into the file directory of the corresponding target platform, the method further includes:
[0116] Determine whether C and C++ functions are needed. If so, add the -enable-languages=c,c++ parameter;
[0117] Determine whether it is not necessary to generate a cross-compilation tool chain that compiles executable codes for other target platforms. If so, add the -disable-multilib parameter; wherein other target platforms refer to all target platforms except the corresponding target platform;
[0118] Accordingly, according to the gcc dependency library and gcc installation parameters, install the cross-compilation tool gcc to the file directory of the corresponding target platform, including:
[0119] According to gcc's dependent libraries, gcc's installation parameters, and added parameters, install the cross-compilation tool gcc to the file directory of the corresponding target platform.
[0120] In this embodiment, it is necessary to establish an initial static gcc compilation tool. Since the installation of gcc depends on third-party libraries such as mpfr, mpc, gmp, isl, and cloog, the general installation method can be as follows:
[0121] Copy contrib / download_prerequisites in the gcc decompression directory to the parent directory and execute it. This step will download, decompress and softlink the libraries that this version of gcc depends on;
[0122] Select different target parameters according to different platforms. For details, please refer to . / configure-help to view the corresponding parameters, which are the same as the target parameters in binutils;
[0123] When only C and C++ functions are needed, gcc needs to add the -enable-languages=c,c++ parameter to save time when compiling source code;
[0124] When you do not need to generate a cross-compiler that compiles executable code for other platforms, add the -disable-multilib parameter. Therefore, the general installation process of gcc is as follows:
[0125] ①. / configure--prefix= / root / cross-compilation / mipsel64 / cross / --target=mips64el-linux--enable-languages=c,c++--disable-multilib&&makeall-gcc&&make install-gcc
[0126] ②. / configure--prefix= / root / cross-compilation / mipsel / cross / --target=mipsel-linux--enable-languages=c,c++--disable-multilib&&makeall-gcc&&makeinstall-gcc
[0127] ③. / configure--prefix= / root / cross-compilation / aarch64 / cross / --target=aarch64-linux--enable-languages=c,c++--disable-multilib&&makeall-gcc&&makeinstall-gcc.
[0128] In this embodiment, a specific process of installing the cross-compilation tool gcc into the file directory of the corresponding target platform is given. Through this embodiment, the cross-compilation tool gcc can be successfully installed into the file directory of the corresponding target platform, and at the same time, it is ensured that the installed gcc can provide tool support for the cross-compilation process.
[0129] Based on the content of the above embodiment, in this embodiment, the obtained system core files applicable to the corresponding target platform are stored in the file directory of the corresponding target platform, including:
[0130] Package and copy the system core files suitable for the corresponding target platform and unzip them to the file directory of the corresponding target platform to ensure the soft link properties of the system core files.
[0131] Among them, when the file linked by the soft link of the system core file has the same access path as the file on the host machine where the target platform is located, the soft link attribute of the system core file is modified so that the file linked by the soft link of the system core file no longer has the same access path as the file on the host machine where the target platform is located.
[0132] In this embodiment, the system core files include one or more of lib, lib64, lib32, / usr / include, / usr / lib, / usr / lib32, / usr / lib64 and / usr / libexec;
[0133] In this embodiment, the system core files that cross-compilation depends on are prepared. Specific address, the system core files are packaged and copied to the sysroot directory: the files that need to be packaged generally include / lib| / lib64| / lib32| / usr / include| / usr / lib| / usr / lib32| / usr / lib64| / usr / libexec, etc.; to ensure the soft link properties, they are packaged in the original platform and directly decompressed to the sysroot directory of the corresponding files of the target platform host. In addition, it should be noted that it is also the properties of the soft link that may cause the failure and error of the soft link after copying to the host. For example, the soft link is linked to the file / usr / lib / a in the original system, but the host system happens to have the file / usr / lib / a, which will cause the soft link to be invalid, which will cause various problems during compilation. Therefore, according to the specific situation, it is necessary to repair the corresponding soft link to the correct position so that the file linked by the soft link of the system core file and the file on the host system no longer have the same access path.
[0134] In this embodiment, the acquired system core files are stored in the file directory of the corresponding target platform. Since these core files are the core files that cross-compilation depends on, storing these core files in the file directory of the corresponding target platform can enable the target code to be cross-compiled to the corresponding target platform to be cross-compiled into code suitable for the corresponding target platform based on the system core files and cross-compilation tools stored in the file directory of the corresponding target platform, thereby completing the cross-compilation work.
[0135] Based on the content of the above embodiment, in this embodiment, the cross-compilation tool chain construction method further includes:
[0136] When the ld script is recorded in libc.so of the target code to be cross-compiled to the corresponding target platform, the libc path that ld.so depends on, which is specified by the ld script, is modified to a path applicable to the target platform;
[0137] When the ld script is recorded in libpthread.so of the target code to be cross-compiled to the corresponding target platform, the libpthread path that ld.so depends on and specified by the ld script is modified to a path applicable to the target platform.
[0138] In this embodiment, it should be noted that modifying the libpthread path that ld.so specified by the ld script depends on to a path applicable to the target platform means: replacing the old path with the actual path where the file with the same name is located on the target platform. For example, the old path of libpthread.so is / usr / bin / libpthread.so, and the actual location of libpthread.so in the arm64 platform is / home / arm64 / sysroot / usr / lib / libpthread.so. Therefore, the old path needs to be replaced with the actual path in the arm64 platform.
[0139] In this embodiment, it should be noted that: the original system's libc.so generally records a ld script, which specifies the path of libc that ld.so depends on, with libc.so being preferred and libc_nonshared.a being second; this path is fixed, so it needs to be modified in advance to the corresponding appropriate path to avoid compilation errors; and similarly there is libpthread.so, which still records a ld script, which specifies the path of libpthread that ld.so depends on, with libpthread.so being preferred and libpthread_nonshared.a being second; at this point, the customized cross tool chain is built.
[0140] In this embodiment, the normal cross-compilation is ensured by modifying the libc path that ld.so depends on and the libpthread path that ld.so depends on specified by the ld script.
[0141] Based on the content of the above embodiment, in this embodiment, the cross-compilation tool chain construction method further includes:
[0142] According to the system core files and cross-compilation tools stored in the file directory of the corresponding target platform, the target code to be cross-compiled to the corresponding target platform is cross-compiled into a code suitable for the corresponding target platform.
[0143] In this embodiment, after the cross-compilation tool chain is constructed, the constructed cross-compilation tool chain is used to cross-compile the target code to be cross-compiled to the corresponding target platform according to the system core files and cross-compilation tools stored in the file directory of the corresponding target platform (the target platform that meets the actual needs of the project), and cross-compile it into code suitable for the corresponding target platform, thereby completing the cross-compilation work that meets the actual needs of the project.
[0144] Figure 2 FIG. 1 is a schematic diagram showing the structure of a cross-compilation tool chain construction device provided by an embodiment of the present invention. Figure 2As shown, the cross-compilation tool chain construction device provided in this embodiment includes: a creation module 21, a first acquisition module 22, a second acquisition module 23 and a construction module 24, wherein:
[0145] A creation module 21 is used to create a file directory for each target platform;
[0146] A first acquisition module 22 is used to acquire source code and third-party library files of cross-compilation tools applicable to each target platform;
[0147] The second acquisition module 23 is used to acquire system core files applicable to each target platform;
[0148] The construction module 24 is used to compile and install the cross-compilation tools applicable to the corresponding target platforms into the file directory of the corresponding target platforms according to the source code and third-party library files of the cross-compilation tools applicable to the corresponding target platforms, and store the obtained system core files applicable to the corresponding target platforms into the file directory of the corresponding target platforms to build a cross-compilation tool chain applicable to each target platform.
[0149] Since the cross-compilation tool chain construction device provided in the embodiment of the present invention can be used to execute the cross-compilation tool chain construction method described in the above embodiment, its working principle and beneficial effects are similar, so they are not described in detail here. For specific contents, please refer to the introduction of the above embodiment.
[0150] In this embodiment, it should be noted that the various modules in the device of the embodiment of the present invention can be integrated into one or deployed separately. The above modules can be combined into one module or further divided into multiple sub-modules.
[0151] Based on the same inventive concept, another embodiment of the present invention provides an electronic device, see Figure 3 , the electronic device specifically includes the following contents: a processor 301, a memory 302, a communication interface 303 and a communication bus 304;
[0152] The processor 301, the memory 302, and the communication interface 303 communicate with each other via the communication bus 304;
[0153] The processor 301 is used to call the computer program in the memory 302. When the processor executes the computer program, all steps of the above-mentioned cross-compilation tool chain construction method are implemented. For example, when the processor executes the computer program, the following process is implemented: creating a file directory for each target platform; obtaining the source code and third-party library files of the cross-compilation tool applicable to each target platform; obtaining the system core files applicable to each target platform; according to the source code and third-party library files of the cross-compilation tool applicable to each target platform, compile and install the cross-compilation tool applicable to the corresponding target platform into the file directory of the corresponding target platform, and store the obtained system core files applicable to the corresponding target platform in the file directory of the corresponding target platform to build a cross-compilation tool chain applicable to each target platform.
[0154] It can be understood that the detailed functions and extended functions that can be executed by the computer program can refer to the description of the above embodiments.
[0155] Based on the same inventive concept, another embodiment of the present invention provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, all the steps of the above-mentioned cross-compilation tool chain construction method are implemented. For example, when the processor executes the computer program, the following process is implemented: creating a file directory for each target platform; obtaining the source code and third-party library files of the cross-compilation tool applicable to each target platform; obtaining the system core files applicable to each target platform; according to the source code and third-party library files of the cross-compilation tool applicable to each target platform, compile and install the cross-compilation tool applicable to the corresponding target platform into the file directory of the corresponding target platform, and store the obtained system core files applicable to the corresponding target platform in the file directory of the corresponding target platform to build a cross-compilation tool chain applicable to each target platform.
[0156] It can be understood that the detailed functions and extended functions that can be executed by the computer program can refer to the description of the above embodiments.
[0157] Based on the same inventive concept, another embodiment of the present invention provides a computer program product, which includes a computer program, which implements all the steps of the above-mentioned associated application startup control method when executed by a processor. For example, when the processor executes the computer program, it implements the following process: creating a file directory for each target platform; obtaining the source code and third-party library files of the cross-compilation tool applicable to each target platform; obtaining the system core file applicable to each target platform; according to the source code and third-party library files of the cross-compilation tool applicable to each target platform, compile and install the cross-compilation tool applicable to the corresponding target platform into the file directory of the corresponding target platform, and store the obtained system core file applicable to the corresponding target platform in the file directory of the corresponding target platform to build a cross-compilation tool chain applicable to each target platform.
[0158] It can be understood that the detailed functions and extended functions that can be executed by the computer program can refer to the description of the above embodiments.
[0159] In addition, the logic instructions in the above-mentioned memory can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0160] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the embodiments of the present invention. Those of ordinary skill in the art may understand and implement them without creative effort.
[0161] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the cross-compilation tool chain construction method described in each embodiment or some parts of the embodiment.
[0162] In addition, in the present invention, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0163] In addition, in the present invention, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, without contradiction.
[0164] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for constructing a cross-compilation tool chain, characterized in that: include: Create file directories for each target platform; Obtain the source code and third-party library files of the cross-compilation tools applicable to each target platform; Get the system core files applicable to each target platform; According to the source code and third-party library files of the cross-compilation tools applicable to each target platform, the cross-compilation tools applicable to the corresponding target platform are compiled and installed into the file directory of the corresponding target platform, and the obtained system core files applicable to the corresponding target platform are stored into the file directory of the corresponding target platform to build a cross-compilation tool chain applicable to each target platform, wherein the file directory of each target platform contains a tool folder, an installation directory folder and a system core file folder; The tool folder is used to store the source code of the cross-compilation tool suitable for the corresponding target platform and the third-party library files; The installation directory folder is used to store the installation files after the source code in the tool folder is compiled and the installation files of the third-party library files; The system core file folder is used to store system core files suitable for the corresponding target platform, wherein the system core files include one or more of lib, lib64, lib32, / usr / include, / usr / lib, / usr / lib32, / usr / lib64 and / usr / libexec; Accordingly, the obtained system core files suitable for the corresponding target platform are stored in the file directory of the corresponding target platform, including: Package and copy the system core files suitable for the corresponding target platform and unzip them to the file directory of the corresponding target platform to ensure the soft link properties of the system core files. When the file linked by the soft link of the system core file has the same access path as the file on the host machine where the target platform is located, the soft link attribute of the system core file is modified so that the file linked by the soft link of the system core file and the file on the host machine where the target platform is located no longer have the same access path, wherein the method further includes: When the ld script is recorded in libc.so of the target code to be cross-compiled to the corresponding target platform, the libc path that ld.so depends on, which is specified by the ld script, is modified to a path applicable to the target platform; When the ld script is recorded in libpthread.so of the target code to be cross-compiled to the corresponding target platform, the libpthread path that ld.so depends on and specified by the ld script is modified to a path applicable to the target platform.
2. The method for constructing a cross-compilation tool chain according to claim 1, characterized in that: The cross-compilation tools include: gcc and binutils; Accordingly, obtain the source code and third-party library files of the cross-compilation tools applicable to each target platform, including: Determine the gcc source code and third-party library files applicable to each target platform; Determine the binutils source code and third-party library files applicable to each target platform.
3. The method for constructing a cross-compilation tool chain according to claim 2, wherein: According to the source code and third-party library files of the cross-compilation tools applicable to each target platform, compile and install the cross-compilation tools applicable to the corresponding target platform into the file directory of the corresponding target platform, including: According to the gcc source code and third-party library files applicable to each target platform, compile gcc and install it to the file directory of the corresponding target platform; According to the binutils source code and third-party library files applicable to each target platform, compile binutils and install it to the file directory of the corresponding target platform.
4. The method for constructing a cross-compilation tool chain according to claim 3, characterized in that: According to the gcc source code and third-party library files applicable to each target platform, compile gcc and install it to the file directory of the corresponding target platform, including: Determine the value of the gcc installation parameter --prefix--target applicable to each target platform; According to the third-party library files and the values of the installation parameters --prefix--target, compile gcc and install it to the file directory of the corresponding target platform; Accordingly, according to the binutils source code and third-party library files applicable to each target platform, compile and install binutils into the file directory of the corresponding target platform, including: Determine the value of the binutils installation parameter --prefix--target applicable to each target platform; Compile and install binutils to the file directory of the corresponding target platform according to the third-party library files and the values of the installation parameters --prefix--target.
5. The method for constructing a cross-compilation tool chain according to claim 4, characterized in that: When compiling and installing gcc to the file directory of the corresponding target platform based on the third-party library files and the value of the installation parameter --prefix--target, determine whether to add -enable-languages=c,c++ based on whether C and C++ functions are needed.
6. The method for constructing a cross-compilation tool chain according to any one of claims 1 to 5, characterized in that: Also includes: According to the system core files stored in the file directory of the corresponding target platform and the compiled and installed cross-compilation tools, the target code to be cross-compiled to the corresponding target platform is cross-compiled into a code suitable for the corresponding target platform.
7. A cross-compilation tool chain construction device, characterized in that: The device is used to implement the cross-compilation tool chain construction method according to any one of claims 1 to 6, and the device comprises: Create a module to create file directories for each target platform; The first acquisition module is used to acquire the source code and third-party library files of the cross-compilation tool applicable to each target platform; The second acquisition module is used to acquire system core files applicable to each target platform; The construction module is used to compile and install the cross-compilation tools suitable for the corresponding target platforms into the file directory of the corresponding target platforms according to the source code and third-party library files of the cross-compilation tools applicable to the corresponding target platforms, and store the obtained system core files suitable for the corresponding target platforms into the file directory of the corresponding target platforms to build a cross-compilation tool chain suitable for each target platform.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of the cross-compilation tool chain construction method as described in any one of claims 1 to 6 are implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the cross-compilation tool chain construction method as described in any one of claims 1 to 6 are implemented.
10. A computer program product, the computer program product comprising a computer program, characterized in that: When the computer program is executed by a processor, the steps of the cross-compilation tool chain construction method as described in any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Cross-compiling environment establishment method for locomotive computer controller of RTEMS
CN106528190A