nvcc:没有这样的文件或目录

时间:2013-02-01 00:14:33

标签: linux compiler-construction cuda nvcc

请原谅我的诺言。我们的研究小组最近购买了一台装有2个NVIDIA Tesla装置的服务器,我负责设置它。

服务器单元正在运行Rocks 6.0。

所以我按照以下说明安装从NVIDIA下载的CUDA SDK:http://docs.nvidia.com/cuda/cuda-getting-started-guide-for-linux/index.html

我尝试编译随SDK提供的示例代码NVIDIA并出现了一堆错误。我想也许可能没有配置Makefile,所以我查看了Stack Overflow并找到了这段测试代码:

using namespace std;

#include <iostream>
#include <string.h>
#include <unistd.h>

int main (int argc, const char *argv[]) {

    //our message
    const char *message = "hello world!";
    size_t size = strlen(message)+1;

    //delcare and allocate a buffer on the device
    char *d_buffer;
    if (cudaMalloc(&d_buffer,size) != cudaSuccess){
        cerr << cudaGetErrorString(cudaGetLastError()) << endl;
        exit(1);
    }

    //copy our message to the device buffer
    if (cudaMemcpy(d_buffer,message,size,cudaMemcpyHostToDevice)
        != cudaSuccess){
        cerr << cudaGetErrorString(cudaGetLastError()) << endl;
        exit(1);
    }

    //declare and allocate a buffer on the host
    char *h_buffer = (char*)malloc(size);
    if (h_buffer == 0){
        cerr << "malloc failed" << endl;
        exit(1);
    }

    //copy the device buffer back to the host
    if (cudaMemcpy(h_buffer,d_buffer,size,cudaMemcpyDeviceToHost)
        != cudaSuccess) {
        cerr << cudaGetErrorString(cudaGetLastError()) << endl;
        exit(1);
    }

    cout << h_buffer << endl;
    cudaFree(d_buffer);
    free(h_buffer);
}

所以按照说明,我用以下代码编译了代码:

nvcc -o hello_cuda hello_cuda.cu

并出现以下错误:

In file included from /usr/local/cuda-5.0/bin/../include/cuda_runtime.h:76,
                 from <command-line>:0:
/usr/local/cuda-5.0/bin/../include/common_functions.h:76:15: error: new: No such file or directory
In file included from /usr/local/cuda-5.0/bin/../include/common_functions.h:162,
                 from /usr/local/cuda-5.0/bin/../include/cuda_runtime.h:76,
                 from <command-line>:0:
/usr/local/cuda-5.0/bin/../include/math_functions.h:7555:17: error: cmath: No such file or directory
/usr/local/cuda-5.0/bin/../include/math_functions.h:7556:19: error: cstdlib: No such file or directory
hello_cuda.cu:11:20: error: iostream: No such file or directory

这些与编译示例代码时得到的错误消息基本相同。我的猜测是编译器配置不正确,因为iostream应该只是C的标准库。

我是如何解决这个问题的想法或指针?这似乎是一个非常简单的问题,但我已经把头发拉了好几天了!

1 个答案:

答案 0 :(得分:1)

您似乎没有正确安装gcc / g ++。示例不需要boost,错误消息指出它找不到标准库(new,cmath,cstdlib)。

从第2.8.1节http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#proper-compiler-install

开始
  

在Linux和Windows上,正确安装的编译器具有某种形式的内部知识,使他们能够找到系统包含文件,系统库和dll,包含与编译器安装本身相关的文件和库,以及包含实现libc的文件和库和libc ++。