A method for checking program dynamic library version compatibility

By adding version information to the dynamic library on the Windows platform to obtain functions and version check logic, the program crash problem caused by the dynamic library version mismatch is solved, and the compatibility check and problem check of the dynamic library version is realized.

CN119759408APending Publication Date: 2025-04-04EASY THINKING HANGZHOU TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411946383.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-27
Publication Date
2025-04-04

AI Technical Summary

Technical Problem

On Windows platforms, the dynamic library version information cannot be checked at runtime, resulting in undefined behavior when the application replaces another version of the dynamic library, and the problem is difficult to troubleshoot.

Method used

Provides a method for checking the version compatibility of the program dynamic library. By writing version information in the API header file and predefined version information in the dynamic library, the version information is written to the dynamic library during compilation, and the version check is performed through the global variable VersionChecker when running. If it is incompatible, the program will be terminated and a log will be generated.

Benefits of technology

Dynamic library version check is performed when the program starts to avoid program crashes, and log the cause of the problem, simplifying the problem investigation process and improving system stability and reliability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119759408A_ABST
    Figure CN119759408A_ABST
Patent Text Reader

Abstract

The invention provides a method for checking the version compatibility of a program dynamic library. When the dynamic library is compiled, version information is written into the dynamic library; before the program is compiled, a version checking macro is added; when the program is compiled, version information is read from an API header file corresponding to the dynamic library, and recorded as the dynamic library version information during program compilation; the program is run, a global variable is constructed, a version checking logic function defined in a global variable constructor is executed, and the version information in the dynamic library is returned, and recorded as the dynamic library version information during program operation; the dynamic library version information during program compilation and the dynamic library version information during program operation are compared, and whether the two are compatible is determined based on the comparison result; the method aims to solve the problem of program crash caused by the incompatibility between the dynamic library version relied on during software operation and the dynamic library version relied on during compilation. When the versions do not match, the program can be terminated in time and a log file can be generated to locate the cause, thereby avoiding program crash.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of library version compatibility checking, and in particular to a program dynamic library version compatibility checking method applied to a Windows platform. Background Art

[0002] After program developers perform version iteration on component libraries (including static libraries, dynamic libraries, and header files), they need to synchronously update the component library version information. When frequent iterations and upgrades are required for component libraries, it is easy for applications to have no corresponding library version compatibility management strategy, resulting in confusion in library versions. That is, the dynamic library version that is dependent on during compilation does not match or is incompatible with the dynamic library version that is dependent on during runtime, which will lead to unexpected errors when the program is running.

[0003] The current solution to the above problems is the soname mechanism:

[0004] The soname is added to the dynamic library to identify the version information of the library. Other programs can specify the version information of the dependent dynamic library when compiling, so as to ensure that the program uses the library version compatible with the one used when compiling at runtime. However, this mechanism is only used in Unix-like systems, including Linux, FreeBSD, Solaris, etc., and cannot be used on Windows platforms.

[0005] Currently on Windows platforms, although dynamic libraries can add version information, this information is only used for display purposes, and the loaded dynamic library version cannot be checked at runtime. This means that if an application replaces a dynamic library with another version that modifies the API / ABI, the continued operation of the program will result in undefined behavior, and it will be difficult to troubleshoot problems. Summary of the invention

[0006] In order to solve the above technical problems, the present invention provides a program dynamic library version check, which aims to prevent and solve the program crash and other difficult-to-check problems in the Windows platform caused by the incompatibility between the dynamic library version relied on during software operation and the dynamic library version relied on during compilation. In this method, the application will check the compatibility of the dynamic library version at the beginning of the operation. When the version does not match, it can terminate the program as soon as it is started and generate a log file to locate the cause, avoiding the program crash; at the same time, it avoids the work of checking the cause of the crash after the program crashes. This method is convenient in design, fast in processing, and has universal applicability.

[0007] The technical solution is as follows:

[0008] A program dynamic library version compatibility checking method, according to a preset version information naming rule, uses a script to write version information into an API header file, and sets version information for a released dynamic library; pre-defines a version information acquisition function in the dynamic library, and the version information acquisition function is used to extract version information;

[0009] When compiling a dynamic library, the version information in the API header file is written into the dynamic library;

[0010] Before compiling the program, add a version check macro in any cpp compilation unit file, the version check macro is used to define a global variable VersionChecker, and a version check logic function is defined in the constructor of the global variable VersionChecker;

[0011] When the program is compiled, the version detection logic function reads the version information from the API header file corresponding to the dynamic library, and records it as the dynamic library version information during program compilation;

[0012] After the program is compiled, run the program and check the dynamic library version using the following method:

[0013] When the program starts, the global variable VersionChecker is first constructed, and the version check logic function defined in the constructor of the global variable VersionChecker is executed; the version check logic function calls the version information acquisition function in the dynamic library, and the version information acquisition function returns the version information saved in the dynamic library, which is recorded as the dynamic library version information during program operation;

[0014] The version check function compares the dynamic library version information during program compilation and the dynamic library version information during program execution, and determines whether the two are compatible based on the comparison result. If they are compatible, the dynamic library version is correct and the program continues to run. If they are not compatible, the dynamic library version is wrong, the version check function actively pops up a window to throw an exception, terminates the program, and stores the comparison result in the program log.

[0015] Furthermore, the version naming rules include the following four:

[0016] Rule 1: major version number.minor version number; such as 1.1;

[0017] Rule 2: Major version number. Minor version number. Revision number; such as 1.1.1;

[0018] Rule 3: Major version number. Minor version number. Revision number. Compile number, such as 1.0.1.1;

[0019] Rule 4: Major version number. Minor version number. Revision number. Compile number. Suffix, such as 1.0.1.1-develop, 0.0.9.0-alpha.

[0020] Furthermore, the version check function compares the program compile-time dynamic library version information with the program run-time dynamic library version information, and according to the comparison result, determines whether the two are compatible in the following four ways:

[0021] Method 1: If the comparison result shows that the major version numbers of the dynamic library version information at program compilation time and the dynamic library version information at program runtime are consistent, then the two are compatible; otherwise, they are incompatible.

[0022] Method 2: If in the comparison result, the major version number and the minor version number of the program compile-time dynamic library version information are consistent with the program run-time dynamic library version information, then the two are compatible, otherwise, they are incompatible;

[0023] Method 3: If in the comparison result, the major version number, minor version number, and revision number of the program compile-time dynamic library version information and the program run-time dynamic library version information are consistent, then the two are compatible; otherwise, they are incompatible;

[0024] Mode 4: If in the comparison result, the program compile-time dynamic library version information is completely consistent with the program run-time dynamic library version information, then the two are compatible; otherwise, they are incompatible.

[0025] Compared with the existing solutions, the present invention has the following advantages:

[0026] 1. Speed: Since global variables are constructed when the program is just started, this method can set global variables to compare the dynamic library version that the program depends on when it is compiled and the dynamic library version that the program depends on when it is running, so as to deal with incompatible problems in time and avoid program crashes.

[0027] 2. Intuitiveness: When the versions do not match, this method can intuitively display the usage of dynamic libraries through log records, helping users quickly locate related problems and facilitate later investigation and replacement. It also eliminates the problem of difficult investigation of the cause of program crashes, avoiding greater economic losses. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] Figure 1 It is a flowchart of a method for checking the compatibility of program dynamic library versions in a specific implementation method. DETAILED DESCRIPTION

[0029] The technical solution of the present invention is described in detail below in conjunction with the accompanying drawings and specific implementation methods.

[0030] A program dynamic library version compatibility checking method uses a script to write version information into an API header file (for external use) according to a preset version information naming rule;

[0031] Such as: / / version information

[0032]

[0033] Set version information for the released dynamic library; when the dynamic library is compiled, write the version information in the API header file into the dynamic library; pre-define the version information acquisition function in the dynamic library, and the version information acquisition function is used to extract the version information;

[0034] For example: pre-define the version information acquisition function Version LIB_API getRuntimeVersion();

[0035] You can get the corresponding library version information Version

[0036] Before compiling a program (in this solution, specifically a program that relies on a dynamic library), add a version check macro to any cpp compilation unit file;

[0037] For example: / / Add version check macro

[0038]

[0039] The version check macro is used to define the global variable VersionChecker. The constructor of the global variable VersionChecker defines the version compatibility detection logic function.

[0040] Such as: / / Version check macro definition

[0041] #define CHECK LIB VERSION\

[0042] static Versionchecker myLibchecker{LIB_BUILD_VERSION,getRuntimeVersion()};

[0043] LIB_BUILD_VERSION is the library version information in the API header file obtained when the program is compiled. getRuntimVersion() is the version information acquisition function of the dynamic library. The constructor of myLibchecker contains the version compatibility detection logic formulated according to the compatibility rules.

[0044] When the program is compiled, the version detection logic function reads the version information in the API header file corresponding to the dynamic library, which is recorded as the dynamic library version information during program compilation;

[0045] After the program is compiled, run the program, such as Figure 1 As shown, use the following method to check the dynamic library version:

[0046] When the program starts, the global variable VersionChecker is first constructed, and the version check logic function defined in the constructor of the global variable VersionChecker is executed; the version check logic function calls the version information acquisition function in the dynamic library, and the version information acquisition function returns the version information saved in the dynamic library, which is recorded as the dynamic library version information during program operation;

[0047] The version check function compares the dynamic library version information during program compilation and the dynamic library version information during program execution. Based on the comparison results, it determines whether the two are compatible. If they are compatible, the dynamic library version is correct and the program continues to run. If they are not compatible, the dynamic library version is wrong. The version check function actively pops up an exception, terminates the program, and stores the comparison results in the program log.

[0048] In specific implementation, the following four version naming rules can be used:

[0049] Rule 1: major version number.minor version number; such as 1.1;

[0050] Rule 2: Major version number. Minor version number. Revision number; such as 1.1.1;

[0051] Rule 3: Major version number. Minor version number. Revision number. Compile number, such as 1.0.1.1;

[0052] Rule 4: Major version number. Minor version number. Revision number. Compile number. Suffix, such as 1.0.1.1-develop, 0.0.9.0-alpha.

[0053] More specifically, the version check function compares the dynamic library version information during program compilation with the dynamic library version information during program execution, and determines whether the two are compatible based on the comparison result:

[0054] Method 1: If the comparison result shows that the major version numbers of the dynamic library version information at program compilation time and the dynamic library version information at program runtime are consistent, then the two are compatible; otherwise, they are incompatible.

[0055] Method 2: If in the comparison result, the major version number and minor version number of the dynamic library version information at program compilation time are consistent with the dynamic library version information at program runtime, then the two are compatible; otherwise, they are incompatible;

[0056] Method 3: If in the comparison result, the major version number, minor version number, and revision number of the dynamic library version information during program compilation are consistent with those during program runtime, then the two are compatible; otherwise, they are incompatible.

[0057] Method 4: If in the comparison result, the dynamic library version information at program compilation time is completely consistent with the dynamic library version information at program runtime, then the two are compatible; otherwise, they are incompatible.

[0058] During specific implementation, the compatibility judgment method is set according to actual detection needs, and this solution does not impose any special restrictions.

[0059] The foregoing description of the specific exemplary embodiments of the present invention is presented for the purpose of illustration and description. The foregoing description is not intended to be exhaustive, nor is it intended to limit the present invention to the precise form disclosed, and it is apparent that many changes and variations are possible in light of the above teachings. The exemplary embodiments are selected and described to explain the specific principles of the present invention and its practical application, so that other technicians in the field can realize and utilize the various exemplary embodiments of the present invention and its different selected forms and modified forms. The scope of the present invention is intended to be limited by the appended claims and their equivalents.

Claims

1. A method for checking the compatibility of a program dynamic library version, using a script to write version information into an API header file according to a preset version information naming rule, and setting version information for a released dynamic library; pre-defining a version information acquisition function in the dynamic library, and the version information acquisition function is used to extract version information; When compiling a dynamic library, the version information in the API header file is written into the dynamic library; Features: Before compiling the program, add a version check macro in any cpp compilation unit file, the version check macro is used to define a global variable VersionChecker, and a version check logic function is defined in the constructor of the global variable VersionChecker; When the program is compiled, the version detection logic function reads the version information from the API header file corresponding to the dynamic library, and records it as the dynamic library version information during program compilation; After the program is compiled, run the program and check the dynamic library version using the following method: When the program starts, the global variable VersionChecker is first constructed, and the version check logic function defined in the constructor of the global variable VersionChecker is executed; the version check logic function calls the version information acquisition function in the dynamic library, and the version information acquisition function returns the version information saved in the dynamic library, which is recorded as the dynamic library version information during program operation; The version check function compares the dynamic library version information during program compilation and the dynamic library version information during program execution, and determines whether the two are compatible based on the comparison result. If they are compatible, the dynamic library version is correct and the program continues to run. If they are not compatible, the dynamic library version is wrong, the version check function actively pops up a window to throw an exception, terminates the program, and stores the comparison result in the program log.

2. The program dynamic library version compatibility checking method according to claim 1, characterized in that: The version naming rules include the following four: Rule 1: major version number.minor version number; Rule 2: Major version number. Minor version number. Revision number; Rule 3: Major version number. Minor version number. Revision number. Compile number; Rule 4: Major version number. Minor version number. Revision number. Compile number. Suffix.

3. The program dynamic library version compatibility checking method according to claim 1 or 2, characterized in that: The version check function compares the program compile-time dynamic library version information with the program run-time dynamic library version information, and determines whether the two are compatible in the following four ways based on the comparison result: Method 1: If the comparison result shows that the major version numbers of the dynamic library version information at program compilation time and the dynamic library version information at program runtime are consistent, then the two are compatible; otherwise, they are incompatible. Method 2: If in the comparison result, the major version number and the minor version number of the program compile-time dynamic library version information are consistent with the program run-time dynamic library version information, then the two are compatible, otherwise, they are incompatible; Method 3: If in the comparison result, the major version number, minor version number, and revision number of the program compile-time dynamic library version information and the program run-time dynamic library version information are consistent, then the two are compatible; otherwise, they are incompatible; Mode 4: If in the comparison result, the program compile-time dynamic library version information is completely consistent with the program run-time dynamic library version information, then the two are compatible; otherwise, they are incompatible.

Citation Information

Cited By

  • Software ecological management method of automatic test equipment and application thereof

    CN121899620A