How to set DLL search path?

I'm making a binding to a DLL. I have the DLL & LIB files, both for 32 & 64 bits, with the same names.
I just have this standard (I think..?) link in my code :

#[link(name = "LibFT260", kind = "dylib")]
extern "system" {
// FT260 General Functions

it's working actually because I put the 64 bits dll & lib files in my top directory with the cargo.toml file.
is it possible to set the directory where those files will be searched and then set the directory according to the architecture (32 or 64 bits) ?


You will have to use a build script I think. To be specific the cargo:rustc-link-search=[KIND=]PATH instruction.

thanks bjorn3,
will have a look this way..

so, just tried and it seems to work. the .exe file is created correctly. so the lib file was found, but then if I run the executable, it can't find the dll file...
it's probably ok, because if I create a 32 & 64 bits version, there will be two executable files, so each one could be in different directory (or only the needed one will be installed) and have the right dll with it.

use std::env;
fn main() {
    let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
    let mut _vendor_dir = "";
    match target_arch.as_str() {
        "x86_64" => _vendor_dir = "./vendor/amd64",
        "x86" => _vendor_dir = "./vendor/i386",
        arch => panic!("x86 or x86_64 architecture needed ! (not {})", arch),
    println!("cargo:rustc-link-search={}", _vendor_dir); // the "-L" flag    

You will have to either include the directory containing the dll in your PATH or copy the dll to the same directory as the executable.

Yep.. thank you :+1:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.