主页 Swift UNIX C Assembly Go Plan 9 Web MCU Research Non-Tech

Why happened error helper_cuda.h No such file or directory

2023-05-03 | C | #Words: 492

When using nvcc in the command line today, an error "helper_cuda.h": No such file or directory appeared. This error message means: During compilation, the helper_cuda.h header file cannot be found (if other xxx.h cannot be found, the following explanations and solutions are also common).

The reason for this problem is that most compilers have only one way to find a header file: 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 has not even been created or set, and it is even less likely to be found. This problem is one of the common problems no matter which compiler is used. nvcc is the latter. I did not find any information about environment variables in the documentation and help files, and copying the header file to the directory of the .cu source code file does not work (but .hpp 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 the header file. ** Personally, I feel that 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. At worst, you can set an environment variable yourself as a parameter of 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 really no header files on the machine, then go to the code source to search carefully and ask the author.

The header file of nvcc is usually placed in a folder named Common (it may be common in lowercase). This folder is where the library files are stored, as follows:

Common

You can see that these are the header files you are looking for. Next, just let nvcc find them. As mentioned above, nvcc needs to use the -I parameter to specify a header file or search a specific directory. The method is as follows:

# Search for header files and other library files in the specified directory, as follows
nvcc.exe -I directory source code file path

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.

I hope these will help someone in need~