I hope the following question is not too basic, but I am somewhat new to C++ in general and am a bit lost right now.
I try to compile c++ code to use it as a module in PyTorch. The example from the CUSTOM C++ AND CUDA EXTENSIONS tutorial works just fine using OSX and clang. However, when I try to import headers from another folder using #include <includepath/Auxiliary/Array.h> with the following setup.py file
from setuptools import setup, Extension
from torch.utils import cpp_extension
setup(name='rotmat_cpp',
ext_modules=[cpp_extension.CppExtension('function_cpp', ['function.cpp'],
include_dirs=['includepath/Basis', 'includepath/Auxiliary'])],
cmdclass={'build_ext': cpp_extension.BuildExtension})
and folder structure
extensions
├── includepath/
│ ├── Auxiliary/
│ │ ├── Array.h
│ │ └── ...
│ └── Basis/
├── setup.py
├── function.cpp
I get the following error
error: 'includepath/Auxiliary/Array.h' file not found with <angled> include; use "quotes" instead
.
It seems to include the files successfully if I change all <...>
to "..."
as suggested, but then I get problems with a namespace I am using and get an error after loading the compiled package into python afterwards.
I tried the same on my Ubuntu machine with gcc and get a slightly different error.
/media/Projects/extensions/function.cpp:1:10: fatal error: includepath/Auxiliary/Array.h: No such file or directory
#include <includepath/Auxiliary/Array.h>
^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Trying to compile using JIT with the extra_include_paths options gives the same error.
How can I include folders to the compilers search path such that #include <includepath/…> works?