- Do not generate a main when generating code from Simulink. You can do this by going into the Configuration Parameters and in the All Parameters tab search for "main". The setting you will want to disable is "Generate an example main program".
- Do not generate a stub main when doing the Polyspace analysis. You can set this by following the documentation provided at the following page: http://www.mathworks.com/help/bugfinder/ref/verifymodelgeneratedcodemaingenerator.html
How can I fix conflicting "main" functions that prevent Code Prover analysis from completing?
조회 수: 6 (최근 30일)
이전 댓글 표시
The code I'm trying to analyze with Code Prover has two "main" functions: a "throwaway" main in the project's main file and the actual main within code auto-generated by Simulink (different definitions between the two). With no efforts to fix the issue, Code Prover gives the error:
declaration of function "main" is incompatible with a declaration in another translation unit (functions have incompatible types or linkage).
I have tried renaming the unused main function with a preprocessing script to prevent the names from conflicting with each other, which allows the analysis to complete successfully, but severely limits the results due to "Procedure" coverage only covering 2% (as seen in the below screenshot of the Dashboard)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/159399/image.png)
I have also tried replacing the unused main's definition to match the auto-generated one, which then just gives me the more general error:
function "main" already defined in another translation unit
Are there other ways to circumvent this problem?
댓글 수: 0
답변 (1개)
Jordan Ross
2017년 1월 9일
Hello,
You were on the right track by removing one of the main functions since it is not allowed to have more than one. Also, it will lead to incompatible types since the main generated by Polyspace is not really a main but a stub function that invokes all of your functions in seemingly illogical order.
You can try the following:
Additionally, you can always try doing the analysis directly from the Simulink model. An example of this can be found in the following page: https://www.mathworks.com/examples/polyspace-/mw/polyspace_bf-ex43674797-generate-and-analyze-code
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Run Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!