Rust linker seeks a LIB, rather than a DLL

穿精又带淫゛_ 提交于 2020-12-10 07:59:07

问题


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

The declaration is like this:

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

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

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

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'

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.

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?

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


回答1:


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.

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



来源:https://stackoverflow.com/questions/63394094/rust-linker-seeks-a-lib-rather-than-a-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!