Rust链接器寻求LIB,而不是DLL

Rust链接器寻求LIB,而不是DLL

问题描述:

我正在Windows上试用Rust。我的代码声明并调用了外部库中的函数。

I'm experimenting with Rust on Windows. My code declares and calls a function in an external library.

声明是这样的:

#[link(name = "Rvea0326nc-64")]
extern "C" {
  fn WeibullSpeedProbability(wa: &f32, wk: &f32, qu: &f32, prob: &f32, theerr: &i32) -> ();
}

(全都是ByRef,因为DLL是Fortran。它是使用Intel编译器构建的。)

(It's all ByRef because the DLL is Fortran. It's built with the Intel compiler.)

请注意,文件名没有扩展名。 DLL位于Rust项目的\target\debug\deps文件夹中。

Note that the file name has no extension. The DLL is in the \target\debug\deps folder of the Rust project.

根据此处的文档
https://doc.rust-lang.org/std/keyword.extern.html ,这应导入Windows上的DLL,但出现错误,因此:

According to the documentation here https://doc.rust-lang.org/std/keyword.extern.html, this should import a DLL on Windows, but I get an error, thus:

error: linking with `link.exe` failed: exit code: 1181 
<SNIP>
= note: LINK : fatal error LNK1181: cannot open input file 'Rvea0326nc-64.lib'

确定足够了,如果我找到并复制生成DLL的* .lib文件,一切正常。 DLL显然无关紧要。

Sure enough, if I find and copy in the *.lib file from which the DLL was generated, everything works fine. The DLL is apparently irrelevant.

我尝试显式添加 .dll。链接名称,但是Rust只是抱怨找不到Rvea0326nc-64.dll.lib。

I have tried explicitly adding ".dll" to the link name, but Rust just complains that it cannot find Rvea0326nc-64.dll.lib.

文档是否错误?我错过了什么吗?

Is the documentation wrong? Have I missed something? Is there a way to get Rust to work with the DLL?

更新:我发现直接运行Rust编译的可执行文件时,DLL是必需的,并且

Update: I found that when running the Rust-compiled executable directly, the DLL is required and the LIB is not.

如果没有在Rust中使用FFI的经验过多,我可以想象编译您的程序,您会需要在计算机上安装 .lib ,以便rustc可以正确检查FFI功能是否正确。然后,当运行生成的二进制文件时,它将在运行时加载 .dll 并使用它。

Without having too much experience with FFI in Rust, I can imagine to compile your program, you will need the .lib installed on your machine, so that rustc can correctly check that the FFI function is correct. Then when the produced binary is run, it loads the .dll at runtime and uses it.

尝试查看生成的二进制文件后是否安装了 .lib 的二进制文件,则无需安装 .lib 即可运行该二进制文件。

Try to see if after producing a binary with the .lib installed, that you can run that binary without the .lib installed.