我有一个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文件时,我收到一个错误,即无法找到库* .a文件 .
所以我的问题是: What is the proper way to reference additional files when using compile_fmu in JModelica?
没有成功,我试过:
# 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中的错误 .
2 回答
尝试将外部库定位在名为您当前所在平台的子文件夹中 . 所以在你的例子中,我将库(libCAdd.a)放在名为linux64的子文件夹中,因为我在64位Linux机器上,然后运行代码 .
如果是一小段C代码,作为最后一种选择,您可以尝试直接在Modelica代码中包含C文件:
希望JModelica人员能尽快给你一个更好的答案 . 您也可以尝试在他们的网站上询问:http://www.jmodelica.org/forum