问题描述
我有一个调用外部 C 函数的 Modelica 函数。目前,我只能使用设置 Advanced.CompileWith64 = 2
我想以这样的方式包装这个函数,即在调用外部函数之前将标志 Advanced.CompileWith64
设置为值 2,然后将其设置为其原始值。
概念上是这样的:
function myFunctionWithWrapper
...
algorithm
originalFlagValue := readFlag(CompileWith64)
setFlag(CompileWith64,requiredFlagValue) "set Advanced.CompileWith64 = 2"
myExternalFunction(...)
setFlag(CompileWith64,originalFlagValue)
end myFunctionWithWrapper
有没有办法从 Modelica 类中读取和设置 Dymola 标志?
解决方法
在带有注释 __Dymola_interactive=true
的函数中,您可以使用它们的常规路径简单地访问这些标志。
function setFlag
protected
Integer old_val;
algorithm
old_val :=Advanced.CompileWith64;
Advanced.CompileWith64 :=2;
// do something
Advanced.CompileWith64 :=old_val;
annotation(__Dymola_interactive=true);
end setFlag;
,
可能还有另一种解决方案。
设置 Advanced.CompileWith64 :=2;
表示 64 位编译和链接。需要它的可能原因是某些外部库仅作为 64 位版本存在。
可以通过更改外部代码来处理这种情况,而不是直接在 LibraryDirectory 中包含 myExternalFunction.lib
,而是有一个包含该库的子目录 win64
。 win32
子目录的不存在和 win64
的存在将强制进行 64 位编译和链接。
(其他平台类似。)