Linking to CUDA Library in Leaf


#1

So I’ve been trying to mess around with Leaf lately, and as someone who’s never written a line of C or C++ in their life I was having trouble getting the examples to build. Even though it might be obvious to everyone else, I thought I’d share my findings.

My issue was that the CUDA binaries weren’t in any of the link-search directories, so the build failed with:

/usr/bin/ld: cannot find -lcudnn
/usr/bin/ld: cannot find -lOpenCL
/usr/bin/ld: cannot find -lOpenCL
/usr/bin/ld: cannot find -lcublas
/usr/bin/ld: cannot find -lcublas

It turns out it’s actually really easy to add link flags to rustc using a cargo build script.

My build.rs just contains the following:

fn main() {
    println!("cargo:rustc-link-search=native=/usr/local/cuda/lib64")
}

Dodgy but it works :smiley:

I also had some help from this little guide for getting CUDA link path stuff set up in Ubuntu.

Does anyone else have any advice on build scripts for someone who’s never had to worry about linking before?


#2

The pkg-config crate can do most of the heavy lifting for since CUDA comes with a pkg-config file, though collenchyma should really be handling that for you. You might want to open an issue on that repo.


#3

Thanks, I don’t really understand it all yet, but are you saying that collenchyma should use something like pkg-config to link to CUDA when using that feature?

I’ll open an issue for it.


#4

Yep


#5

That depends on the distro/provided package doesn’t it? Here on Arch Linux I don’t have a pkg-config file for CUDA.


#6

cudnn definitely no package , looked on ubuntu and mint. ( nor cuda 7.5)

Ben