使用 cc 更改 Rust 传递给 nvcc 的编译参数

Changing the compilation arguments passed to nvcc by Rust using cc

我正在使用 cc 到 link 一个用 C 语言编写到 Rust 的 CUDA 内核。 这是我的 build.rs 文件:

extern crate cc;

fn main() {
    cc::Build::new()
        .cuda(true)
        .flag("-cudart=shared")
        .flag("-gencode")
        .flag("arch=compute_61,code=sm_61")
        .file("kernel/kernel.cu")
        .compile("kernel/kernel.a");
}

我有这个错误:

running: "nvcc" "-ccbin=c++" "-O0" "-Xcompiler" "-ffunction-sections" "-Xcompiler" "-fdata-sections" "-Xcompiler" "-fPIC" "-G" "-Xcompiler" "-g" "-m64" "-Xcompiler" "-Wall" "-Xcompiler" "-Wextra" "-cudart=shared" "-gencode" "arch=compute_61,code=sm_61" "-o" "/home/ltei/Dev/Workspaces/rust_cudnn/target/debug/build/rust_cudnn-df924982e63c2363/out/kernel/kernel.o" "-c" "kernel/kernel.cu" cargo:warning=In file included from /usr/include/cuda_runtime.h:78:0, cargo:warning= from :0: cargo:warning=/usr/include/host_config.h:119:2: error: #error -- unsupported GNU version! gcc versions later than 5 are not supported! cargo:warning= #error -- unsupported GNU version! gcc versions later than 5 are not supported! cargo:warning= ^~~~~ exit code: 1

我知道如果我可以将命令中的 -ccbin=c++ 更改为 -ccbin=clang-3.8 就可以了,但我不知道该怎么做。

我也可以安装另一个版本的 GCC,但我更喜欢第一个解决方案。

您可以将 CXX 环境变量设置为您想要的任何值。

CXX=this-is-my-cpp-compiler cargo build

这将用作 ccbin 的参数:

"nvcc" "-ccbin=this-is-my-cpp-compiler" "-O0" "-Xcompiler" "-ffunction-sections" "-Xcompiler" "-fdata-sections" "-Xcompiler" "-fPIC" "-G" "-Xcompiler" "-g" "-m64" "-Xcompiler" "-Wall" "-Xcompiler" "-Wextra" "-cudart=shared" "-gencode" "arch=compute_61,code=sm_61" "-o" "/private/tmp/c/target/debug/build/c-67ec4fdcff2f35d1/out/kernel/kernel.o" "-c" "kernel/kernel.cu"