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

时间:2018-03-17 23:11:25

标签: cuda linker rust ffi nvcc

我使用cc将用C编写的CUDA内核链接到Rust。 这是我的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");
}

我有这个错误:

  

正在运行:“nvcc”“ - ccbin = c ++”“ - O0”“ - Xcompiler”“ - function-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 =包含在文件中   /usr/include/cuda_runtime.h:78:0,货物:警告=来自   :0:cargo:warning = / usr / include / host_config.h:119:2:   错误:#error - 不支持的GNU版本! gcc版本晚于5   不支持! cargo:warning = #error - 不支持的GNU版本!   不支持5晚以后的gcc版本!货物:警告= ^ ~~~~   退出代码:1

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

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

1 个答案:

答案 0 :(得分:3)

您可以将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"