我有一个Modelica文件,它通过外部库*.a文件在模拟过程中引用c代码。
例如:
model CallAdd
input Real FirstInput(start=0);
input Real SecondInput(start=0);
output Real FMUOutput(start=0);
function CAdd
input Real x(start=0);
input Real y(start=0);
output Real z(start=0);
external "C" annotation(Library = "CAdd", LibraryDirectory = "modelica://CallAdd");
end CAdd;
equation
FMUOutput = CAdd(FirstInput,SecondInput);
annotation(uses(Modelica(version = "3.2.1")));
end CallAdd;在OpenModelica中打开Modelica模型时,所需的文件似乎会自动加载,因为它模拟并给出了适当的结果。
但是,当我试图用JModelica-SDK-1.12编译Modelica文件时,我会收到一个错误,无法找到库*.
所以我的问题是:,在JModelica?中使用compile_fmu时,引用附加文件的正确方法是什么?
但没有成功,我试过:
# Import the compiler function
from pymodelica import compile_fmu
model_name = "CallAdd"
mo_file = "CallAdd.mo"
# Compile the model and save the return argument, for use later if wanted
my_fmu = compile_fmu(model_name, mo_file, target="cs",compiler_options = {'extra_lib_dirs':'C:/ToFolderContainingLib/'})奇怪的是,当我使用JModelica-1.17 (非SDK)时,文件编译得很好,但是结果没有意义。有人建议我尝试SDK版本,看看它是否修复了我上一篇文章here中的错误。
发布于 2016-09-04 13:27:04
尝试将外部库定位到指定为当前平台的子文件夹中。因此,在您的示例中,我会将库(libCAdd.a)放置在名为linux64的子文件夹中,因为我位于64位Linux机器上,然后运行代码。
发布于 2016-08-24 21:58:05
如果是一小部分C代码,作为最后一种选择,您可以尝试将C文件直接包含在Modelica代码中:
external "C" annotation(Include="
// the entire C code here
");希望JModelica的人能很快给你一个更好的答案。你可以试着在他们的网站上问这个问题:http://www.jmodelica.org/forum
https://stackoverflow.com/questions/39133480
复制相似问题