Fatal error: cuda.h: No such file or directory


I successfully installed CUDA 8.0 in my PC and I can see its files by running the following commands in my Ubuntu 16.10:

$ sudo find / -name nvcc


$ sudo find / -name cuda


Then, I got the following source code (has_cuda.c) to check out if CUDA is installed:


int main ()
    int deviceCount;
    cudaError_t e = cudaGetDeviceCount(&deviceCount);
    return e == cudaSuccess ? deviceCount : -1;

But running this code returns me the following error:

$ gcc has_cuda.c 

has_cuda.c:1:17: fatal error: cuda.h: No such file or directory
compilation terminated.

I looked for cuda.h in my directories and found them at the following places:

$ sudo find / -name cuda.h


I am quite rookie on this, so, what can be happening? should I have to export any variable to point out where cuda.h is? how can I do this?


I have never compiled a cuda project myself but I think you will need to link the library to the compiler.

Some quick googling says Nvidia has compiler for this which will handle everything. So you just need to install that and you should be good to go. It’s called NVVC. Once installed just run:

nvcc helloworld.cu -o hello.out

With external libraries like these, you almost always need to link them. You don’t have to do it for the standard library because the linker already knows where to find it.

Answered By – Lasse Jacobs

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published