clang in neovim giving pp_file_not_found error for c++/pytorch basic example
I'm following this very basic c++/pytorch example:
pytorch_installing
And I can walk through this example with no errors. However, when creating the example-app.cpp file (or editing it at any point in time) with neovim, clang throws an error 'torch/torch.h' file not found [clang: pp_file_not_found]. My CMakeLists.txt file looks like this:
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(example-app)

find_package(Torch REQUIRED)
include_directories(SYSTEM /home/username/Downloads/libtorch/)
set(CMAKE_PREFIX_PATH &quot;/home/username/Downloads/libtorch/share/cmake/Torch&quot;)
set(CMAKE_CXX_FLAGS &quot;${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}&quot;)

add_executable(example-app example-app.cpp)
target_link_libraries(example-app &quot;${TORCH_LIBRARIES}&quot;)
set_property(TARGET example-app PROPERTY CXX_STANDARD 14)

This isn't a big issue for me with this small of a project. But I will be working on a larger project with libtorch and would like clang to recognize &lt;torch/torch.h&gt;. There were a couple similar Stackoverflow questions, but no answers.
Update:
I believe this is happening because clang is not seeing torch/torch.h because it is not part of the include paths. I printed the include paths for clang and it was not list. So I tried adding the include paths of libtorch to /usr/include/ but then it has issues seeing other header files referenced by header files I added. So I added the libtorch/include/torch/csrc/api/include/torch/ directory to /usr/include so that it can read #include &lt;torch/torch.h. But then other header files are referenced in those header files with specified directory paths outside of the libtorch/include/torch/csrc/api/include/torch/ path.
For example, libtorch/include/torch/csrc/ contains WindowsTorchApiMacro.h. There are other paths within the libtorch directory that contain more header files. I tried to add all header files to \usr\include but still received an error. I'm sure the package as a whole needs to be used. The original cmake file looks like this:
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(example-app)

find_package(Torch REQUIRED)
set(CMAKE_CXX_FLAGS &quot;${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}&quot;)

add_executable(example-app example-app.cpp)
target_link_libraries(example-app &quot;${TORCH_LIBRARIES}&quot;)
set_property(TARGET example-app PROPERTY CXX_STANDARD 14)

So cmake is able to find and reference all of those header files properly, and I know you can compile it at the command line with clang, but how can clang within neovim (during editing) see this package without error? I thought about using a package manager like vcpkg, but they do not have libtorch available, unfortunately. I can include output from a verbose and successful cmake run if needed.

Since the compilation succeeds with cmake-make, it is possible to ask CMake to generate the compilation database (typically a compile_commands.json file) with cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1.
Once the file is available, it can be read by the autocompletion compiler (clang in this case), which prevents the autocompleter from being lost in the filesystem, because all flags and headers are specified for all compilation units.
The compilation database just needs to be put where the autocompletion plugin expects it to be.
