C语言 错误:cuda_runtime.h:没有那个文件或目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13167598/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 04:15:57  来源:igfitidea点击:

error: cuda_runtime.h: No such file or directory

cgcccudanvcc

提问by skrieder

How can I force gcc to look in /usr/cuda/local/include for cuda_runtime.h?

如何强制 gcc 在 /usr/cuda/local/include 中查找 cuda_runtime.h?

I'm attempting to compile a CUDA application with a C wrapper. I'm running Ubuntu 10.04.

我正在尝试使用 C 包装器编译 CUDA 应用程序。我正在运行 Ubuntu 10.04。

I've successfully compiled my CUDA application into a .so with the following command:

我已使用以下命令成功地将我的 CUDA 应用程序编译为 .so:

nvcc -arch=sm_11 -o libtest.so --shared -Xcompiler -fPIC main.cu

When I try and compile my c wrapper file with the following command:

当我尝试使用以下命令编译我的 c 包装文件时:

gcc -std=c99 -o main -L. -ltest main.c

I receive the error:

我收到错误:

error: cuda_runtime.h: No such file or directory

I've verified that cuda_runtime.h is in fact present in /usr/local/cuda/include

我已经验证 cuda_runtime.h 实际上存在于 /usr/local/cuda/include

回答by skrieder

Using an -I switch allowed gcc to find the cuda_runtime.h file:

使用 -I 开关允许 gcc 找到 cuda_runtime.h 文件:

gcc -std=c99 -I/usr/local/cuda/include -o main -L. -ltest main.c

回答by Alex Punnen

If you are using CMake

如果您正在使用 CMake

find_package(CUDA  REQUIRED)
include_directories("${CUDA_INCLUDE_DIRS}")

回答by Vidhu

Add -isystem /usr/local/cuda-8.0/includeto CXX_INCLUDES in flags.make file.

添加-isystem /usr/local/cuda-8.0/include到 flags.make 文件中的 CXX_INCLUDES。

回答by Yamaneko

We were using CMake but it still wasn't able to find the header files (maybe it is the CMake version that couldn't find the directory ./targets/x86_64-linux/includeor because we have multiple CUDA versions). Setting CPATHand LD_LIBRARY_PATHfixed it for us:

我们正在使用 CMake 但它仍然无法找到头文件(可能是 CMake 版本找不到目录,./targets/x86_64-linux/include或者因为我们有多个 CUDA 版本)。为我们设置CPATHLD_LIBRARY_PATH修复它:

export CPATH=/usr/local/cuda-10.1/targets/x86_64-linux/include:$CPATH
export LD_LIBRARY_PATH=/usr/local/cuda-10.1/targets/x86_64-linux/lib:$LD_LIBRARY_PATH
export PATH=/usr/local/cuda-10.1/bin:$PATH