Opened 5 years ago
Last modified 3 years ago
#5932 accepted defect
DLL needs to be in working directory
Reported by: | Owned by: | Adrian Pop | |
---|---|---|---|
Priority: | high | Milestone: | |
Component: | Run-time | Version: | v1.14.0 |
Keywords: | dll, external, C, C++ | Cc: |
Description
I have been working on creating a library for internal use at my company and we need to have some functions written in C/C++ that interface with the Modelica code.
After reading through the language specifications and some examples I was perfectly able to use the method where you just use the Include statement to add a .c file.
However, I had issues getting the exact same file to work when compiled into a .dll. It would compile just fine, but I would get the following error during the simulation step:
Process crashed Simulation process failed. Exited with code -1073741515.
The .h file is in LibraryName/External/Resources/Include and the .dll is in LibraryName/External/Resources/Library/win64. The code block for the external function is as follows:
function External_Lib "External function in a library to generate signal" input Real t; output Real x; external "C" x = External_Lib(t) annotation( LibraryDirectory = "modelica://LibraryName/External/Resources/Library", Library = "External_Lib", IncludeDirectory = "modelica://LibraryName/External/Resources/Include", Include = "#include \"External_Lib.h\""); end External_Lib;
After trying many different things I found that it will work if I also put the .dll in the working directory of OMEdit. My guess is that the issue is either that found libraries are not properly added to the PATH, or that the DLL dependencies are not properly being included.
Change History (8)
comment:1 by , 5 years ago
Component: | *unknown* → Run-time |
---|---|
Milestone: | Future → 1.16.0 |
Owner: | changed from | to
Status: | new → assigned |
follow-up: 3 comment:2 by , 5 years ago
Status: | assigned → accepted |
---|
Spec doesn't say anything about this. Just about the linking.
Of course, we should add these to the path before running the model.
comment:3 by , 5 years ago
Replying to adrpo:
Spec doesn't say anything about this. Just about the linking.
Shall I open a ticket on the the Modelica Specification tracker?
comment:4 by , 5 years ago
Here is the latest text:
https://specification.modelica.org/master/functions.html#annotations-for-external-libraries-and-include-files
There is nothing about running a model that depends on an external function with a dynamic link library. Is it probably implied even thou' there is this text there
"The Library name and the LibraryDirectory name in the function annotation are mapped to a linkage directive in a compiler-dependent way thereby selecting the object library suited for the respective computer platform."
comment:5 by , 5 years ago
There are multiple references to a "linker" in the specification. Dynamically linked libraries are by linked by the OS instead of by a static linker at compile time, but I guess that may go under the same definition. For example:
The
annotation(Library="libraryName")
, used by the linker to include the library file where the compiled external function is available.
In the case of a dll, the "linker" is the OS.
The
annotation(LibraryDirectory="modelica://ModelicaLibraryName/Resources/Library")
, used to specify a location for library files.
A DLL is by definition a library, so this annotation should also apply to it.
@adrpo, what do you think?
comment:7 by , 4 years ago
Milestone: | 1.17.0 → 1.18.0 |
---|
Retargeted to 1.18.0 because of 1.17.0 timed release.
Obviously we should also look in the Resources paths.
@adrpo, can you please comment on this issue?