使用 DLL 调用 Modelica 外部 C 函数

Modelica External C function call using a DLL

我在 Dymola 中通过两个 DLL 使用两个外部函数。我遇到了一个问题,它让我思考编译器实际上是如何找到外部函数的。因此,两个不同 DLL 中的函数具有相同的名称和相同的输入和输出变量集,但执行不同的任务。

void Execute(int in_1, bool flag_in, bool* flag_out, int* out_1);

我在Modelica的外部函数接口中定义如下:

function testFunc1 

  input Integer in_1;
  input Boolean flag_in;
  output Boolean flag_out;
  output Integer[5] out_1;

  external C Execute(int in_1, bool flag_in, bool* flag_out, int* out_1)   
  annotation(Library = "DLL1");
end testFunc1;

第二个函数是在另一个名为 testFunc2 的 modelica 函数中调用的,就像上面一样。 我观察到的是,由于外部函数具有相同的名称和相同的输入和输出变量集,因此尽管定义了库名称,编译器仍会错误地从其他 DLL 中选择错误的函数并执行它。

我想知道是否有办法强制编译器在查找外部函数时只查看特定的 DLL?或者外部函数根本不应该具有相同的名称?或者有没有更好的方法将DLL引入Modelica?

如果您确实需要将符号命名为相同的东西,请使用 win32 API 中的 LoadLibrary 等。否则,您可能应该为跨工具和跨平台兼容性的函数指定唯一的名称。

这个库是同时有一个 DLL 和一个 LIB 文件还是只有一个 DLL?

如果有 LIB 文件,Dymola 会 link - 这可能会导致上述问题,但如果没有 LIB 文件,Dymola 2016 应该直接转到 DLL。

但使用不同的名称通常更简单。