- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Static linking with extern "C" / Library
Static linking with extern "C" / Library
Static linking with extern "C" / Library
I made a custom Modelica Library the other day wich contains code written in c/c++. That code is being compiled by clang to a .dll and .a (openmodelica 1.17).
The Librarys file tree now looks like this:
Code:
MyLib
│ package.mo
│
├───SomeFolder
│ SomeModel.mo
│ SomeOtherModel.mo
│ package.mo
│ package.order
│
└───Resources
├───Include
│ SomeModelHeader.h
│ SomeOtherModelHeader.h
│
└───Library
└───mingw64
libSomeLibrary.dll.a
SomeLibrary.dll
The library functions are accessed via ExternalObject / extern "C"
Code:
within MyLib.SomeFolder;
type SomeModel
extends ExternalObject;
function constructor "Instantiate Classes and allocate Memory"
output SomeModel someModel;
external "C" someModel = initSomeModel()
annotation(
Library = "SomeLibrary",
Include = "#include \"SomeModelHeader.h\"");
end constructor;
function destructor "Release Class instances and Memory"
input SomeModel someModel;
external "C" closeSomeModel(someModel);
end destructor;
end SomeModel;
When i compile a model using this, the simulation process crashes, because it's not able to find SomeLibrary.dll.
If i manually copy the dll to c:\Users\myUserAppData\Local\Temp\OpenModelica\OMEdit\MyModel simulation works as expected.
Questions:
- Is it possible to add the Resources/Library/mingw64 to the dll search path for the simulation executable
- Is it possible to force openmodellica to do static linking, which would avoid the previous issue.
The Libraries shipped with openmodelica use __iti_dll/__iti_dllNoExport in 'external "C"', but the usage is not documented.
Any hints welcome!
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Static linking with extern "C" / Library