How do I use Polyspace Code Prover for a project with multiple "main" functions?

In my project, I have 3 functions titled "main" in three different subdirectories. When using Polyspace Code Prover, I receive the following error in Polyspace:

Error: main procedure multiply defined
How can I resolve this?

 Risposta accettata

Polyspace Code Prover only accepts one 'main' file per project and analysis, but there are two different workarounds available:
  1. Analyze each "main" function separately.
  1. Rename the functions just for their use in Polyspace, while keeping their name as "main" for all other uses. Do this by inserting unique names, such as “main1" and "main2", inside a ‘#ifdef POLYSPACE’ - ‘#else’ - ‘#endif’ preprocessor. For example, you can add the wrapper below to your "main" functions:
#ifdef POLYSPACE
int psN_main(int argc, int *argv[])
#else
int main(int argc, int *argv[])
#endif 
{
   // main function implementation
   return 0;
}
where N is a number 1-3 (according to your files). Polyspace defined the “POLYSPACE” macro when you run Code Prover analysis on your project with the recommended options, so it defines the function as "psN_main".
Then, you can run the analysis with the "-main-generator" with "-main-generator-calls all" options as shown below:
polyspace-code-prover -sources SubDir1\File1.c,SubDir2\File2.c,SubDir3\File3.c -main-generator -main-generator-calls all
This will generate a new "main" function that calls all functions except inlined ones, and Polyspace will use this generated "main" for its analysis. For more information on these options, including how to set them using the Polyspace user interface, please refer to the documentation pages below:
  • -main-generator:
  • -main-generator-calls:
 
This is a requirement of Polyspace in that each project can only have one effective "main" function as in C/C++ programs.
For more information on Coder Prover assumptions about the ‘main’ function, refer to the documentation below:

Più risposte (0)

Prodotti

Release

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by