Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to statically linking OpenCV with CUDA and use dynamic linking for CUDA #596

Open
ImmortalD opened this issue Jul 25, 2024 · 1 comment

Comments

@ImmortalD
Copy link

ImmortalD commented Jul 25, 2024

I used vcpkg to install OpenCV with CUDA support. I want to statically linking the OpenCV library while using dynamic linking for the CUDA libraries. However, I encountered a problem where the CUDA libraries are also statically linked to the program. I am not sure how to configure it correctly.

install opencv with vcpkg

vcpkg install opencv4[contrib,nonfree,cuda]:x64-windows-static-md

rust config

./.cargo/config.toml

[env]
VCPKGRS_TRIPLET = "x64-windows-static-md"

build.rs

fn main() {
    
    let vcpkgrs_triplet = std::env::var("VCPKGRS_TRIPLET");

    match vcpkgrs_triplet {
        Ok(triplet) => {
            if triplet == "x64-windows-static-md" {
                let cuda_path = std::env::var("CUDA_PATH").expect("CUDA_PATH not set");
                println!("cargo:rustc-link-search=native={}\\lib\\x64", cuda_path);
                println!("cargo:rustc-link-lib=dylib=nppc");
                println!("cargo:rustc-link-lib=dylib=nppial");
                println!("cargo:rustc-link-lib=dylib=nppicc");
                println!("cargo:rustc-link-lib=dylib=nppidei");
                println!("cargo:rustc-link-lib=dylib=nppif");
                println!("cargo:rustc-link-lib=dylib=nppig");
                println!("cargo:rustc-link-lib=dylib=nppim");
                println!("cargo:rustc-link-lib=dylib=nppist");
                println!("cargo:rustc-link-lib=dylib=nppisu");
                println!("cargo:rustc-link-lib=dylib=nppitc");
                println!("cargo:rustc-link-lib=dylib=npps");
                println!("cargo:rustc-link-lib=dylib=cufft");
                println!("cargo:rustc-link-lib=dylib=cublas");
                
                println!("cargo:rustc-link-lib=dylib=cudart");
            }
        }
        Err(_) => {}
    }
}
@twistedfall
Copy link
Owner

twistedfall commented Sep 2, 2024

Can you please post the full output of cargo build -vv after doing a cargo clean? I'd like to see what are the actual link flags are passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants