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.

Include paths in C-Scripts

0 votes

Hi all,

I am using external code (header and source files for specific functions) in a C-Script, e.g.

#include <my_functions.c>

It all works when the included file is in the same directory as the simulation model. If the files are more than a couple, it would be nice to have them in a separate folder, but so far I couldn't manage to use a relative path like

#include "./Lib/my_functions.c"

(same with backslash and/or <> brackets).

Is there any way to use relative paths in this context?


asked Jun 4, 2020 by Sandro Calligaro (12 points)

1 Answer

0 votes

Hi Sandro,

This is possible.  Perhaps your directory structure doesn't match how you are entering the relative paths. 

Attached is a simple example that works.  The external C files are in the "lib" folder that is in the same directory as the PLECS model.

If the files were structured differently, say "proj/models/scriptTest.plecs" and "proj/lib/my_functions.c" then you would change the include to: #include "../lib/my_functions.c"

Hope this helps address your issue.
answered Jun 8, 2020 by Bryan Lieblick (398 points)

Thanks Bryan,

your model works. I modified my #include path accordingly, and it works now.

I'm a bit surprised that to make it work we must not use "./" nor ".\" before the subdirectory name, although dot seems to be standard (both in UNIX and DOS) for referencing the current directory...