c - 使用 DLL 调用 Modelica 外部 C 函数

标签 c function external modelica dymola

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

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

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

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 等。否则,您可能应该为函数指定唯一名称以实现跨工具和跨平台兼容性。

关于c - 使用 DLL 调用 Modelica 外部 C 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33788322/

相关文章:

检查recvfrom() 中的返回地址(C UDP 套接字)

MySQL UDF/存储函数无法识别作为参数传递的表名

resources - 使用 JSFiddle 加载 JS Flot 外部资源

PHP 使用外部磁盘驱动器下载文件

java - android中是否有用于ms office word(.doc/.docx)到(image/html/xml/pdf)转换的Api

C 将整数转换为字符串

c - C 中的 qsort() 用于 char 指针数组

swift - 快速简化功能

function - 你如何返回不可复制的类型?

jquery - 如何编辑外域iframe的内容?