3

I created a C function in test.c

#include <stdio.h>


int Test()
{
    FILE * fp = fopen("C:\\workspace\\test.txt", "rw");
    fprintf(fp, "test hello world");
    fclose(fp);
    return 10;
}

And I defined a state in stateflow of simulink. I used

en: Test();

I specified the file in both Tools->Open Simulation Target->Custom Code->Include List of additional and Include Custom C Code in generated (using absolute path and file name) When I tried to run the model, I got parser error: en: Test(); ^ Function named 'Test' is not a Stateflow Function.

What should I do?

2 Answers 2

4

Got it done by my own. In the "Include Custom C Code in generated:"->Header file tab, I should specify my header file as

#include "test.h"

instead of

test.h

And c file should be specified in "Include list of additional"->Source files as

test.c
Sign up to request clarification or add additional context in comments.

Comments

3

Adding reference to an online example for adding custom C code to Stateflow that will help other users who run into similar issues: http://www.mathworks.com/support/solutions/en/data/1-1727V/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.