Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: cuda_runtime.h: No such file or directory

Tags:

c

gcc

cuda

nvcc

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

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

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

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:

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

like image 497
skrieder Avatar asked Oct 31 '12 21:10

skrieder


3 Answers

If you are using CMake

find_package(CUDA  REQUIRED)
include_directories("${CUDA_INCLUDE_DIRS}")
like image 187
Alex Punnen Avatar answered Sep 17 '22 13:09

Alex Punnen


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

gcc -std=c99 -I/usr/local/cuda/include -o main -L. -ltest main.c
like image 33
skrieder Avatar answered Sep 17 '22 13:09

skrieder


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/include or because we have multiple CUDA versions). Setting CPATH and LD_LIBRARY_PATH fixed it for us:

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
like image 23
Yamaneko Avatar answered Sep 18 '22 13:09

Yamaneko