What should I do if "helper_cuda.h": No such file or directory error occurs when using nvcc (other xxx.h is also the same solution)

When using it on the command line today nvcc, an error occurred “helper_cuda.h”: No such file or directory. This error message means: During compilation, helper_cuda.hthe header file cannot be found ( xxx.hif others cannot be found, then the following explanations and solutions are also common).

The reason for this problem is that most compilers find the header file in one way: find the header file in the directory set in the environment variable. If there is no such header file in the directory stored in the environment variable, it will not be found. This environment variable is not even created or set, and it is even more impossible to find it. This kind of problem is one of the common problems regardless of the compiler used.
nvccIt's the latter, I didn't find any information about environment variables in the documentation and help files, and copying the header files to the .cudirectory of the source code files didn't work (but .hppit seems to work). The official meaning is to add options to the compilation command and use the path as a parameter to point out or search for header files. Personally, this method is much better for small programs or short-term projects, because it will not mess up the environment variables, and you can easily customize the compilation settings without causing confusion. But long-term projects are a bit troublesome, but there are solutions. The big deal is to set an environment variable by yourself as a parameter for the compiled search option. You can also modify this environment variable every time.

The solution is to let the compiler find these header files. Here we assume that there are header files on the machine. If there are no such header files on the machine, then go to the code source to find them and ask the author.

nvccThe header files are generally placed Commonin a folder named (possibly in lowercase common). This folder is the storage library file, as follows:
Please add a picture description

You can see that these are the header files you are looking for, and then you nvcccan find them. As mentioned above, nvccyou need to use -I 参数to specify the header file or search for a specific directory, as follows:

# 在指定目录下查找头文件等库文件,下面的
nvcc.exe -I 目录 源代码文件路径

For example in the above figure, the directory is E:\testcuda\cuda-samples-master\Common\, the source code file path is .\bandwidthTest.cu, and the command is as follows:

nvcc.exe -I E:\testcuda\cuda-samples-master\Common\ .\bandwidthTest.cu

This will compile normally. Hope to help those in need~

Guess you like

Origin blog.csdn.net/qq_33919450/article/details/130461890