- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » difficulty loading external function.
difficulty loading external function.
difficulty loading external function.
I am trying to load the system time in milliseconds from an external C function and keep running into an error. I believe it is modelica and not the C function but just in case these are the functions I am using
C
#include <sys/time.h>
int systm()
{
struct timeval tv;
gettimeofday(&tv, 0);
int tm=(int)tv.tv_usec;
return int;
}
Modelica function:
function systm
annotation(__OpenModelica_Impure = true);
input Real x;
output Real tm;
external "C" tm=systm();
annotation(Include="#include <systm.c>", Include="#include <sys/time.h>",__OpenModelica_Impure = true );
end systm;
Modelica Model:
model test
annotation(Include="#include <systm.c>", Include="#include <sys/time.h>",__OpenModelica_Impure = true );
Real tt;
algorithm
tt:=systm(0);
end test;
The error message I keep getting is
Translation 17:34:42 0:0-0:0 Error building simulator. Buildlog: gcc -falign-functions -msse2 -mfpmath=sse -I"C:/OpenModelica1.9.0//include/omc" -I. -c -o pack.test.o pack.test.c
gcc -falign-functions -msse2 -mfpmath=sse -I"C:/OpenModelica1.9.0//include/omc" -I. -c -o pack.test_records.o pack.test_records.c
g++ -I. -o pack.test.exe pack.test.o pack.test_records.o -I"C:/OpenModelica1.9.0//include/omc" -I. -falign-functions -msse2 -mfpmath=sse -L"C:/OpenModelica1.9.0//lib/omc" -lSimulationRuntimeC -linteractive -lregex -lexpat -static-libgcc -luuid -lole32 -lws2_32 -lsundials_kinsol -lsundials_nvecserial -llapack-mingw -Wl,-Bstatic -lf2c -Wl,-Bdynamic
pack.test.o:pack.test.c.text+0x2c): undefined reference to `systm'
collect2: ld returned 1 exit status
mingw32-make: *** [omc_main_target] Error 1
Re: difficulty loading external function.
You have two different Include annotations. Possibly only the last one was chosen. And since you include the c-file there is no need to include the header anyway.
- sjoelund.se
- 1700 Posts
Re: difficulty loading external function.
I tried removing the extraneous includes and annotations, however i continue to get the same error. In addition I tried renaming the c-file to isolate whether it was the modelica function or the c-file, ithe name stayed the same leading me to believe that the reference that it can't find is the modelica function. The modelica function passes the check test in open modelica, so I am still unsure of the problem.
Re: difficulty loading external function.
It seems the generated code for simulations do not use the Include annotation. Only when called as a shared object. Should be easy enough to fix.
- sjoelund.se
- 1700 Posts
Re: difficulty loading external function.
What works for now is:
Code:
function systm
annotation(__OpenModelica_Impure=true, Include="#include \"systm.c\"");
input Real x;
output Real tm;
external "C" tm=systm();
end systm;
If you had two different annotation sections, one was ignored. This is what I will fix.
- sjoelund.se
- 1700 Posts
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » difficulty loading external function.