- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » ModelicaMessages from external functions
ModelicaMessages from external functions
ModelicaMessages from external functions
Dear all,
I've been working on importing a set of C-functions using external functions and external objects. I get error-msgs such as;
ttExternal.Loop.o:ttExternal.Loop.c.text+0x1884): undefined reference to `ModelicaFormatMessage'
ttExternal.Loop.o:ttExternal.Loop.c.text+0x18cd): undefined reference to `ModelicaMessage'
even though I have included
#include "ModelicaUtilities.h"
in my c-files. In Dymola the ModelicaMessages works fine for the same code. Do I have to provide a path in OM? It's doesn't complain about the include of "ModelicaUtilites.h", rather I get the above error messages, so I'm a bit confuzzled atm.
Thanks for any help!
/patrik
PS. in the same project I have problems with the change operator. It doesn't seem to work for booleans? First I had an array of Booleans, then I tried the single array elements and after that I tried the x <> pre(x) on the whole array, didn't work. Finally I got it to work with x[ i ] <> pre(x[ i ]). As far as I know all of the constructs should work according to the Modelica-specification. Do you have a compliance list for Modelica functions etc?
Re: ModelicaMessages from external functions
Did you specify Library={"ModelicaExternalC"} in your function?
- sjoelund.se
- 1700 Posts
Re: ModelicaMessages from external functions
I have the same problem as pmeijer had in May.
I specified Library={"ModelicaExternalC", "mylib.o"} in my function in addition to my own mylib.o, but with no effect.
I still get the message "undefined reference to `ModelicaError'". In my OpenModelica directory a 'ModelicaExternalC' file does not exist, so which library should be included here?
Re: ModelicaMessages from external functions
You should have /usr/lib/omc/libModelicaExternalC.a. And anyway you should get a message saying it could not find that library while linking. Also note GCC is a one-phase linker, so the order matters. Try "mylib.o" before "ModelicaExternalC" and see if that helps.
- sjoelund.se
- 1700 Posts
Re: ModelicaMessages from external functions
YES, it works!
I have this file lib/omc/libModelicaExternalC.a and it works if I put "ModelicaExternalC" at the end of the Library list.
I always thought that OpenModelica uses the given library filename as it is. But OpenModelica also searches for lib<name>.a files, right?
I also want my model to run with Dymola. ModelicaExternalC works in Dymola too, because there is the file bin/lib/ModelicaExternalC.lib. Dymola seems to append always ".lib" automatically. Because of this I copied my own (gcc compiled) mylib.o file and renamed the copy into mylib.o.lib.
Isn't there a Modelica code working for Dymola AND OpenModelica without having the lib file twice (.o and .o.lib)?
Re: ModelicaMessages from external functions
Of course there is:
Library={"MyLib","ModelicaExternalC"}
Then use two files: libMyLib.a for OpenModelica/GCC and MyLib.lib for Dymola and OpenModelica/MSVC.
- sjoelund.se
- 1700 Posts
Re: ModelicaMessages from external functions
Ok. If I really need two files, it is no major problem. Although I have Dymola and OpenModelica under Windows....
But it only works, if I copy the mylib.lib and the libmylib.a file to the directories the tools like. OpenModelica seems to like the libmylib.a file in lib/omc directory, while Dymola likes another directory for the mylib.lib file. I don't think it is a good idea to copy my file libmylib.a into the OpenModelica program directory in lib/omc. So I'm confused now about the paths the files to place. Is there a solution for this?
Re: ModelicaMessages from external functions
Code:
function f
external "C" annotation(LibraryDirectory="file:///opt/local/lib",Library="MyLib");
end f;
model M
algorithm
f();
end M;
You can also use a modelica:// URI like MyPackage/Resources/Library. The default is to search MyPackage/Resources/Library/$PLATFORM, where $PLATFORM is win32 and mingw32 for the Windows version of OpenModelica.
- sjoelund.se
- 1700 Posts
Re: ModelicaMessages from external functions
I use OpenModelica 1.8.1. OMShell says: "Warning: Requested package Modelica of version 3.2, but this package was already loaded with version 3.1. You might experience problems if these versions are incompatible."
I understand this as confirmation that I use Modelica 3.1, which was always fine for me (until now).
The 'LibraryDirectory' keyword is new in Modelica 3.2 and it seems as if my OpenModelica 1.8.1 installation ignores the 'LibraryDirectory' command. I tried an absolute path 'LibraryDirectory="C:/dir1/dir2"' as well as a 'modelica://' path. Both did not work. Is it possible?
Then I switched from 'loadModel(Modelica)' to 'loadModel(Modelica,{"3.2"})' . The message disappears. But OpenModelica still just looks in the default path. Do I have to install Modelica 1.9.0?
Re: ModelicaMessages from external functions
Yes. There are other things you can do though (if you really do want the older omc).
setLinkerFlags("-L/c/dir1/dir2") might work
Your best bet is:
setEnvironmentVar("MODELICAUSERCFLAGS", "-L/c/dir1/dir2")
Since I believe the simulate flag for this was not added until recently:
simulate(ModelName, cflags = "-L/c/dir1/dir2")
- sjoelund.se
- 1700 Posts
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » ModelicaMessages from external functions