Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include Path Directory

Tags:

c++

I'm somewhat confused on how to add header files to C++ projects. Often times when I attempt to use a #include "genericheader.h", it says that the file can not be found. However, the file generally exists, it's simply that the path is not written correctly So my question, by using the #include "genericheader.h", where does the compiler look for this file? Does it look in the current directory of the file that is trying to include it? Or is it dependent on things such as the IDE?

If I'm trying to include a header file, is it generally best practice to have it placed within the directory of the current file trying to include it?

Apologies for the noobish question. Thanks!

like image 685
Izzo Avatar asked Mar 12 '16 04:03

Izzo


People also ask

What is an include path?

2.2.2.3 Include Paths System include paths are standard locations to find source code tags, such as the header files in /usr/include and its subdirectories on Unix-like operating systems. You can add and remove system include paths using the following commands: Command: semantic-add-system-include dir &optional mode ¶

What is include path in C?

In the include path, you can specify a comma-separated list of any combination of HFS directories, PDSs, and search path configuration files. The system include path is used to search for system header files.

Where is the include path C++?

In the same directory as the file that contains the #include statement. In the directories of the currently opened include files, in the reverse order in which they were opened. The search begins in the directory of the parent include file and continues upward through the directories of any grandparent include files.

What is path and directory?

Each file and directory can be reached by a unique path, known as the path name, through the file system tree structure. The path name specifies the location of a directory or file within the file system. Note: Path names cannot exceed 1023 characters in length.


1 Answers

You are using quoted form of include directive, it searches for include files in this order:

  1. In the same directory as the file that contains the #include statement.
  2. In the directories of the currently opened include files, in the reverse order in which they were opened. The search begins in the directory of the parent include file and continues upward through the directories of any grandparent include files.
  3. Along the path that's specified by each /I compiler option.
  4. Along the paths that are specified by the INCLUDE environment variable.

Further reading: https://msdn.microsoft.com/en-us/library/36k2cdd4.aspx

like image 153
Chandresh Avatar answered Oct 01 '22 13:10

Chandresh