linux - nvcc: 没有那个文件或目录

标签 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

我尝试编译 NVIDIA 随 SDK 提供的示例代码,但遇到了一堆错误。我想可能是 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 的标准库。

有什么想法或建议可以解决这个问题吗?这似乎是一个非常简单的问题,但我已经为此绞尽脑汁好几天了!

最佳答案

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

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

On both Linux and Windows, properly installed compilers have some form of internal knowledge that enables them to locate system include files, system libraries and dlls, include files and libraries related the compiler installation itself, and include files and libraries that implement libc and libc++.

关于linux - nvcc: 没有那个文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14637578/

相关文章:

linux - linux内核中stop_sched_class有什么用

arrays - 对 bash 脚本中的每个文件使用 exec

c++ - 推力 CUDA 找到每个组(段)的最大值

cuda - 内核中的新运算符..奇怪的行为

c++ - 将字符数组传递给 CUDA 内核

linux - jenkins 应该有什么权限来执行 shell 命令而不是不安全的?

Python 子进程 AttributeError

compiler-construction - 需要一个后端编译器

java - Xcode: 'Generics are not supported in -source 1.3' 编译器错误?

c++ - 简单的 "Hello World"样式程序在执行开始后很快关闭