Using header file in C-script

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.

ptest.plecs (10.6 KB)

controller.h (34 Bytes)

controller.c (134 Bytes)

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.

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.