I have looked in The C++ Programming Language to try to find the answer to this. When I #include "my_dir/my_header.hpp"
in a header, where does it look for this file? Is it relative to the header, relative to the source file that included it, or something else?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
Implementation defined. See what is the difference between #include <filename> and #include “filename”.
It depends on what syntax you use in the #include directive:
Quoted form : This form instructs the preprocessor to look for include files in the same directory of the file that contains the #include statement, and then in the directories of any files that include (#include) that file. The preprocessor then searches along the path specified by the /I compiler option, then along paths specified by the INCLUDE environment variable.
Angle-bracket form : This form instructs the preprocessor to search for include files first along the path specified by the /I compiler option, then, when compiling from the command line, along the path specified by the INCLUDE environment variable.
The path-spec is a filename optionally preceded by a directory specification. The filename must name an existing file. The syntax of the path-spec depends on the operating system on which the program is compiled.
This information should be in the documentation for your specific C++ Preprocessor Reference, the above is taken from this article on MSDN which has more on the subject.
The complete search path may depend on the compiler. For Visual Studio, the documentation states that it:
Its implementation defined. Those #include"my_dir/xxy.hpp" on a file (for example foo.h) are relative to the file (foo.h and my_dir would be on the same level at the directory hierarchy). With some (most?) compilers, you can use a flag to use these < > (#include
I know that gcc / g++ provides the -I flag. So you could use g++ -I /home [...] indicating that the xxy.hpp file is located in the /home/my_dir/ directory. I havent used any other C/C++ compiler in a while now.
for GCC version <= 3.0, the angle-bracket form does not generate a dependency between the included file and the including one. So if you want that your makefile automatically generates dependencies, you must use the quoted form for the files that should be included in the dependency tree.
It is relative to both the current source file and to any search paths given (-I for gcc).