In the error message, you will see that the folder [your source folder]\bin\x86_64-pc-windows-gnu added to the library path. You must put your library in this folder. You may also need to add the prefix 'lib' to the library name.
Here is a small example that works for me:
C file with welcome feature:
#include <stdio.h> void hello() { printf("Hello from C!\n"); }
Compile the C file into the libhello.c shared library using MinGW:
gcc -shared -o libhello.dll hello.c
Rust main.rs file:
#[link(name = "hello")] extern { fn hello(); } fn main() { unsafe { hello(); } }
Now you should place (copy) libhello.dll in the subfolder \ bin \ x86_64-pc-windows-gnu:
+ bin + --- x86_64-pc-windows-gnu + --- libhello.dll + main.rs
And you have to compile it with
rustc main.rs
Please note that to run main.exe you also need a copy of libhello.dll next to main.exe or on the system path.
source share