Please take a minute to review and accept our Terms of Use.
Welcome to the PLECS User Forum, where you can ask questions and receive answers from other members of the community.

Many technical questions regarding PLECS are answered on the Technical Solutions page of our website. Tutorial videos, specific application examples, and pre-recorded webinars are available on our YouTube page. Please follow us on LinkedIn for the latest Plexim news.

Using header file in C-script

0 votes
44 views
I'm trying to run a simulation where I have a C-script block, and I want to include a ".h" file containing only function prototypes.

Here's a small setup showing this problem.

On the same folder as the simulation file, I have a "controller.h" file and a "controller.c" file. The "controller.h" file only contains the prototype for a function called "control". The function itself is defined in the "controller.c" file.

In my C-script block, I call the "control" function. The simulation works when I include the "controller.c" file in the C-script "Code Declarations" section, but it does not work if I include the "controller.h" file, the header file containing the function's prototype. In this case, I get an error telling me that the function "control" is undefined.

What I am missing?

I have attached a simple simulation example and the header and source files.
asked Sep 15 by Marco Guerreiro (12 points)

1 Answer

0 votes
With the PLECS C-Script block you cannot link against external libraries, so you must include your external code as source code.  In other words, you must include the "controller.c" file in the Code Declarations section, as you have done so far.
answered Sep 16 by Bryan Lieblick (826 points)
I see. Thank you for your reply.

I would be great, though, if we could link against external libraries. But I must imagine it is probably not that simple.
...