首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在JModelica中引用外部文件

在JModelica中引用外部文件
EN

Stack Overflow用户
提问于 2016-08-24 21:42:43
回答 2查看 323关注 0票数 1

我有一个Modelica文件,它通过外部库*.a文件在模拟过程中引用c代码。

例如:

代码语言:javascript
复制
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时,引用附加文件的正确方法是什么?

但没有成功,我试过:

代码语言:javascript
复制
# 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中的错误。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-09-04 13:27:04

尝试将外部库定位到指定为当前平台的子文件夹中。因此,在您的示例中,我会将库(libCAdd.a)放置在名为linux64的子文件夹中,因为我位于64位Linux机器上,然后运行代码。

票数 2
EN

Stack Overflow用户

发布于 2016-08-24 21:58:05

如果是一小部分C代码,作为最后一种选择,您可以尝试将C文件直接包含在Modelica代码中:

代码语言:javascript
复制
external "C"  annotation(Include="
// the entire C code here
");

希望JModelica的人能很快给你一个更好的答案。你可以试着在他们的网站上问这个问题:http://www.jmodelica.org/forum

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39133480

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档