Adaptation system and method for realizing computer language cross-platform
By designing a cross-platform adaptation system, the compatibility problem of traditional computer languages in different system environments is solved, cross-platform compatibility is achieved, labor costs are reduced, and R&D personnel are allowed to focus on the implementation of business logic.
Patent Information
- Application Number
- CN202410841949.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-27
- Publication Date
- 2024-09-13
AI Technical Summary
Traditional computer languages cannot run directly in different system environments, resulting in compatibility issues and R&D personnel need to spend a lot of time making adaptive adjustments, which increases labor costs.
A cross-platform adaptation system is designed, including a system adaptation module, a data conversion module and a third-party library calling module. By obtaining the type and version of the target system, the data type and length are converted, and a library file suitable for the target system is generated. , optimize the dependencies of third-party libraries and achieve cross-platform compatibility.
The compatibility of computer languages is improved, allowing R&D personnel to focus on the implementation of business logic without having to deal with compatibility issues with different operating systems, reducing labor costs.
Smart Images

Figure CN118642779A
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer technology, and in particular relates to a system and method for implementing cross-platform adaptation of computer languages. Background Art
[0002] Traditional computer languages cannot run directly in different system environments. There will be a lot of errors when compiling and running, and R&D personnel need to spend a lot of time to make adaptive adjustments and modifications. This is because different operating systems provide different APIs and system calls. Traditional computer languages directly or indirectly use the operation library and API of a specific operating system when running, so that the computer language can only run on that specific operating system. For example, if the computer language used on a 32-bit system uses a 32-bit operation library and API, the 64-bit system cannot run this version of the computer language, and there is a compatibility problem. Summary of the invention
[0003] In order to overcome the above-mentioned technical defects, the present invention provides a system and method for realizing cross-platform adaptation of computer languages, so as to improve the compatibility of computer languages, so that R&D personnel can focus on the implementation of business logic without spending a lot of time dealing with compatibility issues of different operating systems, thereby reducing labor costs.
[0004] In order to solve the above problem, the first aspect of the present invention provides a system for implementing cross-platform adaptation of computer languages, comprising:
[0005] System adaptation module, used to obtain the type and version of the target system;
[0006] A data conversion module, used for converting the data type and data length of the computer language into the data type and data length under the target system standard according to the type and version of the target system;
[0007] The third-party library calling module is used to generate library files suitable for the target system according to the type and version of the target system.
[0008] Furthermore, the system adaptation module includes:
[0009] A system version adaptation unit, used to detect and obtain the type and version of the target system according to the architecture information of the target system;
[0010] The function adaptation unit is used to configure the corresponding operation library functions and API functions according to the type and version of the target system.
[0011] Furthermore, the third-party library call module includes:
[0012] Analysis unit, used to analyze the dependencies and architecture of third-party libraries;
[0013] An optimization unit, used to optimize the dependencies of third-party libraries according to the above analysis results, the type and version of the target system;
[0014] The library file generation unit is used to cross-compile the source code of the third-party library and generate library files suitable for the target system.
[0015] Furthermore, the computer language is C language.
[0016] A second aspect of the present invention provides a method for implementing cross-platform adaptation of a computer language, which is applied to the above-mentioned adaptation system and comprises the following steps:
[0017] Get the type and version of the target system and configure the corresponding function;
[0018] According to the type and version of the target system, the data type and data length of the computer language are converted into the data type and data length under the target system standard;
[0019] Generate library files suitable for the target system based on the type and version of the target system.
[0020] Furthermore, the method of obtaining the type and version of the target system and configuring the corresponding function includes:
[0021] Use the compiler to run conditional compilation instructions to detect the architecture information of the target system;
[0022] According to the architecture information of the target system, obtain the memory address width, version and type of the target system;
[0023] Match the corresponding operation library functions and API functions according to the version and type of the target system.
[0024] Furthermore, generating a library file suitable for the target system according to the type and version of the target system includes:
[0025] Analyze the dependencies and architecture of third-party libraries;
[0026] Optimize the dependencies of third-party libraries based on the above analysis results, the type and version of the target system;
[0027] Cross-compile the source code of the third-party library to generate library files suitable for the target system.
[0028] A third aspect of the present invention provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the above method when executing the computer program.
[0029] A fourth aspect of the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the steps of the above method when executed by a processor.
[0030] Compared with the prior art, the present invention has the following beneficial effects:
[0031] The present invention discloses an adaptation system and method for realizing cross-platform computer language. The adaptation system comprises a system adaptation module, a data conversion module and a third-party library calling module. The system adaptation module is used for obtaining the type and version of a target system; the data conversion module is used for converting the data type and data length of the computer language into the data type and data length under the target system standard according to the type and version of the target system; the third-party library calling module is used for generating a library file suitable for the target system according to the type and version of the target system; by processing and adapting the system differences of the versions and types of operating systems (such as 32-bit and 64-bit, Windows and Android, etc.), data types and third-party library calling, the compatibility of the computer language can be improved, so that the research and development personnel can focus on the realization of business logic without spending a lot of time on processing the compatibility issues of different operating systems, and the labor cost can be reduced. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] The specific embodiments of the present invention are further described in detail below in conjunction with the accompanying drawings, wherein:
[0033] Figure 1 This is a schematic diagram of the structure of the system for implementing cross-platform computer language adaptation described in Example 1;
[0034] Figure 2 This is a flowchart of the method for implementing cross-platform adaptation of computer languages described in Example 2;
[0035] Figure 3 This is a schematic diagram of the structure of the computer device described in Example 3;
[0036] Marking description: 100, system adaptation module; 110, system version adaptation unit; 120, function adaptation unit; 200, data conversion module; 300, third-party library call module; 310, analysis unit; 320, optimization unit; 330, library file generation unit; 400, function module. DETAILED DESCRIPTION
[0037] The preferred embodiments of the present invention are described below in conjunction with the accompanying drawings. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present invention, and are not used to limit the present invention.
[0038] Example 1
[0039] This embodiment discloses a system for implementing cross-platform adaptation of computer languages, such as Figure 1 , including a system adaptation module 100, a data conversion module 200 and a third-party library calling module 300, wherein the system adaptation module 100 is used to obtain the type and version of the target system; the data conversion module 200 is used to convert the data type and data length of the computer language into the data type and data length under the target system standard according to the type and version of the target system; the third-party library calling module 300 is used to generate a library file suitable for the target system according to the type and version of the target system.
[0040] Specifically, the system adaptation module 100 includes a system version adaptation unit 110 and a function adaptation unit 120. The system version adaptation unit 110 is used to detect and obtain the type and version of the target system according to the architecture information of the target system. During the compilation process, the compiler uses conditional compilation instructions (such as #if defined(__x86_64__)||defined(_WIN64)#define COMPATIBLE_LIB_64#else#define COMPATIBLE_LIB_32#endif) to detect the architecture of the target system, obtain the architecture information of the target system, and select the appropriate memory address width according to the architecture information. The compiler makes judgments based on some special macros customized according to the architecture of the target system, such as judging that the target system is a 64-bit Windows or other 64-bit system according to conditions such as __x86_64__, _WIN64, etc., otherwise it is a 32-bit system or a 16-bit system.
[0041] The function adaptation unit 120 is used to configure the corresponding operation library function and API function according to the type and version of the target system, unify the differences in the operation libraries and APIs of different operating systems, and avoid compatibility issues caused by different operating systems. When inputting _sleep() under Windows, the function under the correct system is automatically selected and called according to the currently compiled target system through the _WIN64 condition, "void my_sleep(unsigned int seconds){#ifdef_WIN32 Sleep(seconds*1000);#else sleep(seconds);#endif}", the Sleep function of the Windows system accepts milliseconds, and the sleep function of the Unix-like system accepts seconds, so that the computer language can be used normally regardless of whether it is compiled on Windows or Linux, thereby improving its compatibility. In one embodiment, the function adaptation unit 120 is connected to the function module 400, and the function module 400 includes a Windows operation library and a corresponding API, an Android operation library and a corresponding API, a Linux operation library and a corresponding API, a Hongmeng operation library and a corresponding API, an Euler operation library and a corresponding API, and a third-party extension interface operation library and a corresponding API. The function module 400 provides a unified interface for the function adaptation unit 120 by encapsulating system calls of different operating systems, thereby improving compatibility.
[0042] The data conversion module 200 is used to convert the data type and data length of the computer language into the data type and data length under the target system standard according to the type and version of the target system. In one embodiment, the typedef keyword can be used for data conversion to adapt to the data types of different operating systems. For example, the data type int of the computer language is 2 bytes and the data type long is 4 bytes. According to the type and version of the target system, the data type int of the target system is obtained as 4 bytes. The typedef keyword is used to define int32_t to point to long, and the data type int in the computer language on the target system is converted to int32_t, so that the data type and data length of the computer language can be converted according to the target system standard.
[0043] Specifically, the third-party library calling module 300 includes an analysis unit 310, an optimization unit 320 and a library file generation unit 330. The analysis unit 310 is used to analyze the dependencies and architecture of the third-party library and obtain the dependencies between the third-party library and other libraries or function modules. The optimization unit 320 is used to optimize the dependencies of the third-party library according to the above analysis results, the type and version of the target system; when the dependencies of the third-party library are not available on the target system, the dependencies are modified to point to the function module. The library file generation unit 330 is used to cross-compile the source code of the third-party library and generate a library file suitable for the target system so that the third-party library can run normally on the target system.
[0044] In one embodiment, the computer language is C language.
[0045] The system version adapter unit obtains the memory address width of the target system and the type and version of the target operating system; the function adapter unit unifies the operation libraries and APIs of different operating systems, allowing developers to ignore the differences in the underlying operating systems and improve R&D efficiency. The data conversion module uses the typedef keyword to convert data to avoid compatibility issues caused by data types and data sizes, and optimizes the dependencies of third-party libraries through the third-party library call module, so that third-party libraries can run on the target operating system, improving compatibility and reliability.
[0046] Example 2
[0047] Based on the same inventive concept, the embodiment of the present application also provides an adaptation method for implementing computer language cross-platform, which is applied to the above-mentioned adaptation system for implementing computer language cross-platform. The implementation scheme for solving the problem provided by the method is similar to the implementation scheme recorded in the above-mentioned system, so the specific limitations in one or more embodiments of the adaptation method for implementing computer language cross-platform provided below can be referred to the limitations of the adaptation system for implementing computer language cross-platform above, and will not be repeated here.
[0048] In one embodiment, a method for implementing cross-platform adaptation of a computer language is disclosed, such as Figure 2 , including the following steps:
[0049] S1. Get the type and version of the target system and configure the corresponding function.
[0050] Specifically, obtaining the type and version of the target system and configuring the corresponding function include:
[0051] Use the compiler to run conditional compilation instructions to detect the architecture information of the target system;
[0052] According to the architecture information of the target system, obtain the memory address width, version and type of the target system;
[0053] Match the corresponding operation library functions and API functions according to the version and type of the target system.
[0054] S2. According to the type and version of the target system, the data type and data length of the computer language are converted into the data type and data length under the target system standard.
[0055] S3. Generate a library file suitable for the target system according to the type and version of the target system.
[0056] Specifically, generating a library file applicable to the target system according to the type and version of the target system includes:
[0057] Analyze the dependencies and architecture of third-party libraries;
[0058] Optimize the dependencies of third-party libraries based on the above analysis results, the type and version of the target system;
[0059] Cross-compile the source code of the third-party library to generate library files suitable for the target system.
[0060] For other specific implementation details, please refer to Example 1, which will not be repeated here.
[0061] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0062] Example 3
[0063] Each module in the above-mentioned system for implementing cross-platform adaptation of computer languages can be implemented in whole or in part by software, hardware, or a combination thereof. Each of the above-mentioned modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each of the above modules.
[0064] In one embodiment, a computer device is provided. The computer device may be a server or terminal of an integrated scheduler. The internal structure diagram thereof may be as follows: Figure 3 As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data such as the mapping relationship between the shared video memory area and the virtual machine, the total load of the virtual machine, etc. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a method for realizing cross-platform adaptation of computer languages is implemented.
[0065] Those skilled in the art will understand that Figure 3 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0066] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:
[0067] Get the type and version of the target system and configure the corresponding function;
[0068] According to the type and version of the target system, the data type and data length of the computer language are converted into the data type and data length under the target system standard;
[0069] Generate library files suitable for the target system based on the type and version of the target system.
[0070] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0071] Use the compiler to run conditional compilation instructions to detect the architecture information of the target system;
[0072] According to the architecture information of the target system, obtain the memory address width, version and type of the target system;
[0073] Match the corresponding operation library functions and API functions according to the version and type of the target system.
[0074] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0075] Analyze the dependencies and architecture of third-party libraries;
[0076] Optimize the dependencies of third-party libraries based on the above analysis results, the type and version of the target system;
[0077] Cross-compile the source code of the third-party library to generate library files suitable for the target system.
[0078] Example 4
[0079] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0080] Get the type and version of the target system and configure the corresponding function;
[0081] According to the type and version of the target system, the data type and data length of the computer language are converted into the data type and data length under the target system standard;
[0082] Generate library files suitable for the target system based on the type and version of the target system.
[0083] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0084] Use the compiler to run conditional compilation instructions to detect the architecture information of the target system;
[0085] According to the architecture information of the target system, obtain the memory address width, version and type of the target system;
[0086] Match the corresponding operation library functions and API functions according to the version and type of the target system.
[0087] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0088] Analyze the dependencies and architecture of third-party libraries;
[0089] Optimize the dependencies of third-party libraries based on the above analysis results, the type and version of the target system;
[0090] Cross-compile the source code of the third-party library to generate library files suitable for the target system.
[0091] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0092] The technical features of the above embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0093] The above description is only a preferred embodiment of the present invention and does not limit the present invention in any form. Therefore, any modification, equivalent change and modification made to the above embodiment based on the technical essence of the present invention without departing from the technical solution of the present invention are still within the scope of the technical solution of the present invention.
Claims
1. A system for implementing cross-platform adaptation of computer languages, characterized in that: include: System adaptation module, used to obtain the type and version of the target system; A data conversion module, used for converting the data type and data length of the computer language into the data type and data length under the target system standard according to the type and version of the target system; The third-party library calling module is used to generate library files suitable for the target system according to the type and version of the target system.
2. The adaptation system according to claim 1, characterized in that: The system adaptation module includes: A system version adaptation unit, used to detect and obtain the type and version of the target system according to the architecture information of the target system; The function adaptation unit is used to configure the corresponding operation library functions and API functions according to the type and version of the target system.
3. The adaption system according to claim 1, characterized in that: The third-party library call modules include: Analysis unit, used to analyze the dependencies and architecture of third-party libraries; An optimization unit, used to optimize the dependencies of third-party libraries according to the above analysis results, the type and version of the target system; The library file generation unit is used to cross-compile the source code of the third-party library and generate library files suitable for the target system.
4. The adaption system according to claim 1, characterized in that: The computer language is C language.
5. A method for implementing cross-platform adaptation of a computer language, applied to the adaptation system according to any one of claims 1 to 4, characterized in that: The steps include: Get the type and version of the target system and configure the corresponding function; According to the type and version of the target system, the data type and data length of the computer language are converted into the data type and data length under the target system standard; Generate library files suitable for the target system based on the type and version of the target system.
6. The adaptation method according to claim 5, characterized in that: The method of obtaining the type and version of the target system and configuring the corresponding function includes: Use the compiler to run conditional compilation instructions to detect the architecture information of the target system; According to the architecture information of the target system, obtain the memory address width, version and type of the target system; Match the corresponding operation library functions and API functions according to the version and type of the target system.
7. The adaptation method according to claim 5, characterized in that: The method of generating a library file suitable for the target system according to the type and version of the target system includes: Analyze the dependencies and architecture of third-party libraries; Optimize the dependencies of third-party libraries based on the above analysis results, the type and version of the target system; Cross-compile the source code of the third-party library to generate library files suitable for the target system.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 5 to 7 are implemented.
9. A 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 method according to any one of claims 5 to 7 are implemented.
Citation Information
Cited By
Cross-platform WebView packaging device and method based on conditional compiling
CN120994177A
