opencv-rust
opencv-rust copied to clipboard
How to statically linking OpenCV with CUDA and use dynamic linking for CUDA
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(_) => {}
}
}
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