C source file compiling and packaging method and system based on MWORKS platform
By integrating compilation and packaging functions into the MWORKS platform, parsing and generating library files, the cumbersome problem of users having to rely on third-party tools is solved, achieving efficient and secure compilation of C source files and library generation, which is suitable for scenarios with high code confidentiality requirements.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-21
- Publication Date
- 2026-03-13
AI Technical Summary
The existing MWORKS platform lacks built-in compilation and packaging tools, requiring users to rely on third-party compilation environments to manually write scripts, which leads to cumbersome and error-prone operations, increases the barrier to entry and development costs, and complicates cross-platform and cross-environment compilation.
The compilation and packaging functions are integrated into the MWORKS platform to obtain configuration information, parse functions in C source files, select exported functions, generate header files, and call the compilation toolchain to generate static or dynamic library files.
It simplifies the operation process, improves development efficiency, and ensures code security, making it suitable for industrial and scientific research scenarios with high requirements for code confidentiality.
Smart Images

Figure CN121658002A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer software programming and integration, and more specifically, to a method and system for compiling and packaging C source files based on the MWORKS platform. Background Technology
[0002] MWORKS is an integrated development environment (IDE) widely used for system modeling and simulation. It provides powerful function calling capabilities, allowing users to integrate external C language functions into their models to extend simulation capabilities or implement specific functionalities. In practical applications, many companies or organizations, due to confidentiality requirements or intellectual property protection needs, are unwilling or unable to provide the source code of C language functions, instead providing functional interfaces in the form of static libraries (such as .lib and .a files) or dynamic libraries (such as .dll and .so files).
[0003] However, the existing MWORKS platform does not provide built-in compilation and packaging tools. If users need to compile C source files into library files, they must rely on third-party compilation environments (such as Visual Studio, MinGW, etc.) and manually write compilation scripts or configure project files. This process is not only cumbersome and error-prone, but also requires users to have a high level of knowledge of compilation toolchains, increasing the barrier to entry and development costs.
[0004] Furthermore, different organizations may use different compilers, library dependencies, and compilation options, further increasing the complexity of cross-platform and cross-environment compilation. Therefore, there is an urgent need for a user-friendly C source file compilation and packaging solution integrated within the MWORKS platform to simplify the operation process, improve development efficiency, and ensure code security and confidentiality. Summary of the Invention
[0005] This invention addresses the technical problems existing in the prior art by providing a method and system for compiling and packaging C source files based on the MWORKS platform, overcoming the cumbersome process of compiling and packaging C source files in the past.
[0006] According to a first aspect of the present invention, a method for compiling and packaging C source files based on the MWORKS platform is provided, comprising: Integrate compilation and packaging functionality into the MWORKS platform, obtain configuration information, and configure the corresponding compilation toolchain based on the configuration information. Parse all functions in the input C source file and select all or some of the functions as exported functions; Based on the selected exported functions, a header file is generated, which contains the declarations of all exported functions; Based on the configuration information, generate compilation response files and link response files for all exported functions, and call the compilation toolchain to perform compilation and packaging operations to generate corresponding static library files or dynamic library files.
[0007] Based on the above technical solution, the present invention can also be improved as follows.
[0008] Optionally, the configuration information includes the compiler type and bitness selected by the user for the runtime environment required by the static or dynamic library files generated from the C source files.
[0009] Optionally, the parsing of all functions in the input C source file and the selection of all or some functions as exported functions includes: The functions in one or more C source files selected through the graphical interface of the MWORKS platform are parsed, and all the parsed functions are displayed in a list format. Select one or more functions from the list as exported functions as required. These exported functions are included in the generated static library file or dynamic library file.
[0010] Optionally, the process of parsing all functions in the input C source file and selecting all or some of the functions as exported functions further includes: Determine whether each exported function depends on other static or dynamic library files. If yes, add the static or dynamic library files that the exported function depends on; otherwise, do not add other static or dynamic library files. The step of determining whether each exported function depends on other static or dynamic library files includes: If the content of the exported function needs to call the function content in other static library files or dynamic library files, then the exported function depends on other static library files or dynamic library files.
[0011] Optionally, if so, then add the static library file or dynamic library file that the exported function depends on, and then further include: The system automatically parses the name and path information of the added static or dynamic library file and adds the path information of the name to the compilation and linking parameters in the compilation toolchain.
[0012] Optionally, the process of parsing all functions in the input C source file and selecting all or some of the functions as exported functions further includes: Based on one or more output C source files, determine whether the header files of the C source files need to be referenced during the compilation and packaging process. If so, add the directory path of the header files that need to be referenced in the C source files so that the corresponding header files of the C source files can be found based on the directory path during the compilation and packaging process.
[0013] Optionally, the process of parsing all functions in the input C source file and selecting all or some of the functions as exported functions further includes: Add pre-compiled macro definitions for the exported functions as required, and convert the pre-compiled macro definitions into the corresponding format based on the compiler type; Customize compilation options as needed and incorporate them into the compilation command. These compilation options include optimization level and / or warning level.
[0014] According to a second aspect of the present invention, a C source file compilation and packaging system based on the MWORKS platform is provided, comprising: The acquisition module is used to integrate compilation and packaging functions on the MWORKS platform, acquire configuration information, and configure the corresponding compilation toolchain according to the configuration information. The parsing module is used to parse all functions in the input C source file and select all or some functions as exported functions; The generation module is used to generate a header file containing the declarations of all exported functions, based on the selected exported functions; The compilation and packaging module is used to generate compilation response files and linking response files for all exported functions according to the configuration information, and to call the compilation toolchain to perform compilation and packaging operations to generate corresponding static library files or dynamic library files.
[0015] According to a third aspect of the present invention, an electronic device is provided, including a memory and a processor, wherein the processor is configured to implement the steps of a C source file compilation and packaging method based on the MWORKS platform when executing a computer management program stored in the memory.
[0016] According to a fourth aspect of the present invention, a computer-readable storage medium is provided, on which a computer management class program is stored, wherein when the computer management class program is executed by a processor, the steps of a method for compiling and packaging C source files based on the MWORKS platform are implemented.
[0017] This invention provides a method and system for compiling and packaging C source files based on the MWORKS platform. By integrating compilation and packaging functions into the MWORKS platform, users can complete operations such as compiling C source files, managing dependencies, and generating library files on the MWORKS platform without relying on external tools. This invention significantly improves development efficiency and code security, and is suitable for industrial and scientific research scenarios with high requirements for code confidentiality. Attached Figure Description
[0018] Figure 1 A flowchart illustrating a method for compiling and packaging C source files based on the MWORKS platform, as provided in one embodiment of the present invention; Figure 2 A flowchart illustrating an overall process for compiling and packaging C source files based on the MWORKS platform, as provided in one embodiment of the present invention; Figure 3 A structural block diagram of a C source file compilation and packaging system based on the MWORKS platform provided in one embodiment of the present invention; Figure 4 A schematic diagram of the hardware structure of a possible electronic device provided by the present invention; Figure 5 This is a schematic diagram of the hardware structure of a possible computer-readable storage medium provided by the present invention. Detailed Implementation
[0019] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention. In addition, the technical features of the various embodiments or individual embodiments provided by the present invention can be arbitrarily combined with each other to form feasible technical solutions. Such combinations are not constrained by the order of steps and / or structural composition patterns, but must be based on the ability of those skilled in the art to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection claimed by the present invention.
[0020] To address the shortcomings of the existing technology, this invention discloses a method for compiling and packaging C source files based on the MWORKS platform. By integrating compilation and packaging functions into the MWORKS platform, users can complete operations such as compiling C source files, managing dependencies, and generating library files without relying on external tools. This invention significantly improves development efficiency and code security, and is suitable for industrial and scientific research scenarios with high requirements for code confidentiality.
[0021] Figure 1 A flowchart illustrating a method for compiling and packaging C source files based on the MWORKS platform, as provided in one embodiment of the present invention, is shown below. Figure 1 As shown, the method mainly includes the following steps: Step 1: Integrate the compilation and packaging function on the MWORKS platform, obtain the configuration information, and configure the corresponding compilation toolchain according to the configuration information.
[0022] Understandably, the compilation and packaging functionality is first integrated into the MWORKS platform, and then the C source files are compiled and packaged using the compilation and packaging functionality integrated into the MWORKS platform.
[0023] The system retrieves configuration information, including compiler type and bitness. This configuration information is determined by the runtime environment required by the static or dynamic library files generated from the C source files. For example, the compiler type (GCC, MSVC, etc.) and its bitness (32-bit or 64-bit) will be specified, and the appropriate compilation toolchain will be automatically configured based on the selected compiler type and bitness.
[0024] Step 2: parse all functions in the input C source file and select all or some of the functions as exported functions.
[0025] Understandably, the MWORKS platform provides a graphical interface through which users can select one or more C language source files (.c files). The MWORKS platform supports multi-selection and batch import of folders.
[0026] For the selected C source file, all functions in the selected C source file are automatically parsed and displayed to the user in list form. The user can select one or more functions from the list as exported functions. Subsequently, these exported functions are compiled and packaged to generate static library files or dynamic library files.
[0027] In some embodiments of the present invention, the process of parsing all functions in the input C source file and selecting all or some of the functions as exported functions further includes: Determine whether each exported function depends on other static or dynamic library files. If yes, add the static or dynamic library files that the exported function depends on; otherwise, do not add other static or dynamic library files. The step of determining whether each exported function depends on other static or dynamic library files includes: If the content of the exported function needs to call the function content in other static library files or dynamic library files, then the exported function depends on other static library files or dynamic library files.
[0028] Understandably, based on all selected exported functions, it's determined whether each exported function depends on other static or dynamic library files. If an exported function depends on other static or dynamic library files, then that static or dynamic library file is added to the MWORKS platform. Subsequently, the name and path information of each exported function's dependent static or dynamic library file can be added to the compilation and linking parameters of the compiler toolchain.
[0029] Specifically, when determining whether each exported function depends on other static or dynamic library files, if the content of the exported function requires calling the function content of other static or dynamic library files, it indicates that the exported function depends on those other static or dynamic library files. Otherwise, the exported function does not depend on any other static or dynamic library files.
[0030] In some embodiments of the present invention, all functions in the input C source file are parsed, and all or some of the functions are selected as exported functions, and the method further includes: Based on one or more input C source files, determine whether the header files of the C source files need to be referenced during the compilation and packaging process. If so, add the directory path of the header files that need to be referenced in the C source files so that the corresponding header files of the C source files can be found based on the directory path during the compilation and packaging process.
[0031] Understandably, after a user selects one or more C source files, it can be determined whether each C source file needs to reference its header file during the compilation and packaging process. If so, the directory path of the header file to be referenced by the C source file is added to the MWORKS platform, so that the corresponding header file of the C source file can be found based on the directory path during the compilation and packaging process.
[0032] In some embodiments of the present invention, the process of parsing all functions in the input C source file and selecting all or some of the functions as exported functions further includes: Add pre-compiled macro definitions for the exported functions as required, and convert the pre-compiled macro definitions into the corresponding format based on the compiler type; Customize compilation options as needed and incorporate them into the compilation command. These compilation options include optimization level and / or warning level.
[0033] Understandably, if it is necessary to define the parameter symbols in the exported function, the corresponding pre-compiled macro definition needs to be added. When the exported function is compiled later, the pre-compiled macro definition is converted into the corresponding format based on the compiler type.
[0034] When it is necessary to enable optimization or warnings for the compilation results of exported functions, you can customize the compilation options as needed and merge the custom compilation options into the compilation command. Subsequently, the exported functions are compiled according to the compilation command.
[0035] Step 3: Generate a header file based on the selected exported functions. The header file contains the declarations of all exported functions.
[0036] Understandably, a header file is generated based on the selected exported functions to store the declarations of all exported functions, so that it is known which exported functions are compiled and packaged later.
[0037] Step 4: Generate compilation response files and linking response files for all exported functions based on the configuration information, and call the compilation toolchain to perform compilation and packaging operations to generate the corresponding static library files or dynamic library files.
[0038] Understandably, based on the configuration information—namely, the compiler type and bitness—a compilation response file and a linker response file are generated for each exported function. The compilation toolchain then performs a compilation and packaging operation on these files, generating static or dynamic library files corresponding to all exported functions.
[0039] Figure 2 This paper presents an overall flowchart of a C source file compilation and packaging method based on the MWORKS platform according to an embodiment of the present invention, which specifically includes the following steps: 1. Enable the compilation and packaging function: In the MWORKS platform, select the "Shared Library Generation" function entry and click to open; 2. Select compiler type and bitness: Users can select the compiler and bitness to use from the built-in compiler in MWORKS and the automatically detected user-defined compiler; 3. Select C source files: Users select one or more .c files through the file browser; 4. Parse C source functions and select exported functions: Use a Python script to call Clang, which has lexical and syntax analysis capabilities, to extract all functions and display them in a list. Users can select the functions they want to export as needed. 5. Add dependency libraries and automatically resolve paths: When users add static or dynamic libraries that C source files depend on, the dependency library names and paths are automatically resolved and added to the compilation and linking parameters; 6. Configure header file paths, macro definitions, and compilation options: Users can select the directory containing one or more header files through the file browser and manually add the required macro definitions and compilation options; 7. Modify output configuration: Users can specify the name of the generated shared library and the output path, and choose whether to generate header files; 8. Generate response files: Generate a compilation response file containing all compilation parameters based on the user's selections in the preceding steps; generate a linking response file containing all linking parameters. 9. Compilation: Invokes the user-selected compiler and linker to generate the shared library files; 10. Output results: A pop-up window indicates successful compilation and generates the required shared library files and header files (if selected); or a pop-up window indicates compilation failure and generates a build.log file in the user-selected output path to display compilation error information for the user to view.
[0040] Figure 3 This diagram illustrates a C source file compilation and packaging system architecture based on the MWORKS platform, according to an embodiment of the present invention. Figure 3 As shown, the system includes an acquisition module 301, a parsing module 302, a generation module 303, and a compilation and packaging module 304, wherein: The acquisition module 301 is used to integrate compilation and packaging functions on the MWORKS platform, acquire configuration information, and configure the corresponding compilation toolchain according to the configuration information. The parsing module 302 is used to parse all functions in the input C source file and select all or some functions as exported functions; The generation module 303 is used to generate a header file containing the declarations of all exported functions based on the selected exported functions; The compilation and packaging module 304 is used to generate compilation response files and linking response files for all exported functions according to the configuration information, and call the compilation toolchain to perform compilation and packaging operations to generate corresponding static library files or dynamic library files.
[0041] It is understood that the C source file compilation and packaging system based on the MWORKS platform provided by this invention corresponds to the C source file compilation and packaging method based on the MWORKS platform provided in the foregoing embodiments. The relevant technical features of the C source file compilation and packaging system based on the MWORKS platform can be referred to the relevant technical features of the C source file compilation and packaging method based on the MWORKS platform, and will not be repeated here.
[0042] Please see Figure 4 , Figure 4 This is a schematic diagram illustrating an embodiment of the electronic device provided in this invention. For example... Figure 4 As shown, an embodiment of the present invention provides an electronic device 400, including a memory 410, a processor 420, and a computer program 411 stored in the memory 410 and executable on the processor 420. When the processor 420 executes the computer program 411, it implements the steps of a C source file compilation and packaging method based on the MWORKS platform.
[0043] Please see Figure 5 , Figure 5 This is a schematic diagram illustrating an embodiment of a computer-readable storage medium provided by the present invention. (See diagram below.) Figure 5 As shown, this embodiment provides a computer-readable storage medium 500, on which a computer program 511 is stored. When the computer program 511 is executed by a processor, it implements the steps of a C source file compilation and packaging method based on the MWORKS platform.
[0044] The present invention provides a method and system for compiling and packaging C source files based on the MWORKS platform, which has the following beneficial effects: 1. Simplified operation process: Users can complete compilation and packaging without leaving the MWORKS environment, greatly reducing the complexity and time cost of operation; 2. Improve code security: Prevent source code leakage and meet corporate confidentiality and intellectual property protection requirements; 3. Improve development efficiency: Automate tedious steps such as dependency paths and response file generation, reducing human error; 4. Supports flexible configuration: Users can select compilers, exported functions, dependency libraries, compilation options, etc., as needed to adapt to various compilation scenarios; 5. Facilitates integration and reuse: The generated library files can be directly used for MWORDS model integration, improving code reusability and project collaboration efficiency.
[0045] It should be noted that the descriptions of each embodiment in the above embodiments have different focuses. For parts that are not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0046] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0047] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0048] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0049] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0050] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including both the preferred embodiments and all changes and modifications falling within the scope of the invention.
[0051] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, this invention also intends to include these modifications and variations.
Claims
1. A method for compiling and packaging C source files based on the MWORKS platform, characterized in that, include: Integrate compilation and packaging functionality into the MWORKS platform, obtain configuration information, and configure the corresponding compilation toolchain based on the configuration information. Parse all functions in the input C source file and select all or some of the functions as exported functions; Based on the selected exported functions, a header file is generated, which contains the declarations of all exported functions; Based on the configuration information, generate compilation response files and link response files for all exported functions, and call the compilation toolchain to perform compilation and packaging operations to generate corresponding static library files or dynamic library files.
2. The method for compiling and packaging C source files based on the MWORKS platform according to claim 1, characterized in that, The configuration information includes the compiler type and bitness selected by the user for the runtime environment required by the static or dynamic library files generated from the C source files.
3. The method for compiling and packaging C source files based on the MWORKS platform according to claim 1, characterized in that, The process involves parsing all functions in the input C source file and selecting all or some of these functions as exported functions, including: The functions in one or more C source files selected through the graphical interface of the MWORKS platform are parsed, and all the parsed functions are displayed in a list format. Select one or more functions from the list as exported functions as required. These exported functions are included in the generated static library file or dynamic library file.
4. The method for compiling and packaging C source files based on the MWORKS platform according to claim 1 or 3, characterized in that, The process involves parsing all functions in the input C source file, selecting all or some of them as exported functions, and then further including: Determine whether each exported function depends on other static or dynamic library files. If yes, add the static or dynamic library files that the exported function depends on; otherwise, do not add other static or dynamic library files. The step of determining whether each exported function depends on other static or dynamic library files includes: If the content of the exported function needs to call the function content in other static library files or dynamic library files, then the exported function depends on other static library files or dynamic library files.
5. The method for compiling and packaging C source files based on the MWORKS platform according to claim 4, characterized in that, If so, then add the static library file or dynamic library file that the exported function depends on, and then further include: The system automatically parses the name and path information of the added static or dynamic library file and adds the name and path information to the compilation and linking parameters in the compilation toolchain.
6. The method for compiling and packaging C source files based on the MWORKS platform according to claim 1, characterized in that, The process involves parsing all functions in the input C source file, selecting all or some of them as exported functions, and then further including: Based on one or more input C source files, determine whether the header files of the C source files need to be referenced during the compilation and packaging process. If so, add the directory path of the header files that need to be referenced in the C source files so that the corresponding header files of the C source files can be found based on the directory path during the compilation and packaging process.
7. The method for compiling and packaging C source files based on the MWORKS platform according to claim 2, characterized in that, The process involves parsing all functions in the input C source file, selecting all or some of them as exported functions, and then further including: Add pre-compiled macro definitions for the exported functions as required, and convert the pre-compiled macro definitions into the corresponding format based on the compiler type; Customize compilation options as needed and incorporate them into the compilation command. These compilation options include optimization level and / or warning level.
8. A C source file compilation and packaging system based on the MWORKS platform, characterized in that, include: The acquisition module is used to integrate compilation and packaging functions on the MWORKS platform, acquire configuration information, and configure the corresponding compilation toolchain according to the configuration information. The parsing module is used to parse all functions in the input C source file and select all or some functions as exported functions; The generation module is used to generate a header file containing the declarations of all exported functions, based on the selected exported functions; The compilation and packaging module is used to generate compilation response files and linking response files for all exported functions according to the configuration information, and to call the compilation toolchain to perform compilation and packaging operations to generate corresponding static library files or dynamic library files.
9. An electronic device, characterized in that, It includes a memory and a processor, wherein the processor is used to implement the steps of the C source file compilation and packaging method based on the MWORKS platform as described in any one of claims 1-7 when executing computer management programs stored in the memory.
10. A computer-readable storage medium, characterized in that, It stores a computer management program, which, when executed by a processor, implements the steps of the C source file compilation and packaging method based on the MWORKS platform as described in any one of claims 1-7.