Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

External c function

External c function

I'm trying to use an external c function in v1.9.3, and I get an error that the file does not exist. I have the file located in several places within the folder structure, but it still tells me that the file does not exist. I have also verified the spelling, and have tried it with the library as a single file, but nothing seems to get rid of the error. Please advise.

Re: External c function

The rest of the error is (with names removed to make it more generic):
In file included from[<LibraryName>.<ModelName>_functions.c:7:
[[<LibraryName>.<ModelName>_includes.h:4:25: error: <ExternalFunctionName>.c: No such file or directory
mingw32-make: *** [<LibraryName>.<ModelName>_functions.o] Error 1
mingw32-make: *** Waiting for unfinished jobs....
Compilation process failed. Exited with code 2.

Re: External c function

Is the file located in modelica://<LibraryName>/Resources/Include, where files are located unless your annotations say otherwise?

Re: External c function

I tried creating that directory, and placing the file in that directory, but it still didn't seem to recognize it. The annotation line I have (someone else wrote it for me, so I'm not sure why it was done this way or what it means) is:
  annotation(Include = "#include \"ModelicaRNG.c\"");

This is the annotation in a modelica function that calls it. With that annotation, should the file be in the same folder as the modelica function?

Thanks.

Re: External c function

From my limited expirience with OpenModelica I would say it is not possible to call external c function via modelica paths.
At least this is not possible with external table data for the CombiTable models.

The solutions for this was to use the loadResource function to convert modelica paths to absoulte file paths

So try to load the external file with the output of this code line:

Code:

Modelica.Utilities.Files.loadResource("modelica://<LibraryName>/Resources/Include") 

There are 0 guests and 0 other users also viewing this topic