Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the environment variable for GCC/G++ to look for .h files during compilation: LIBRARY_PATH, C_PATH, C_INCLUDE_PATH or CPLUS_PATH?

Tags:

gcc

Is there an environment variable for GCC/G++ to look for .h files during compilation?

I google my question, there are people say LIBRARY_PATH, C_PATH, C_INCLUDE_PATH, CPLUS_PATH, so which one is it?

like image 667
michael Avatar asked Mar 23 '10 03:03

michael


People also ask

Where does GCC look for header files?

GCC looks for headers requested with #include " file " first in the directory containing the current file, then in the directories as specified by -iquote options, then in the same places it would have looked for a header requested with angle brackets.

Which option in GCC is used to specify the location of the .h files?

gcc -I adds include directory of header files.

Does GCC use environment variables?

These environment variables control the way that GCC uses localization information which allows GCC to work with different national conventions. GCC inspects the locale categories LC_CTYPE and LC_MESSAGES if it has been configured to do so. These locale categories can be set to any value supported by your installation.

What is Cpath environment variable?

CPATH specifies a list of directories to be searched as if specified with -I , but after any paths given with -I options on the command line. This environment variable is used regardless of which language is being preprocessed.


2 Answers

From: http://gcc.gnu.org/onlinedocs/cpp/Environment-Variables.html

CPATH C_INCLUDE_PATH CPLUS_INCLUDE_PATH OBJC_INCLUDE_PATH 

Each variable's value is a list of directories separated by a special character, much like PATH, in which to look for header files. The special character, PATH_SEPARATOR, is target-dependent and determined at GCC build time. For Microsoft Windows-based targets it is a semicolon, and for almost all other targets it is a colon.

CPATH specifies a list of directories to be searched as if specified with -I, but after any paths given with -I options on the command line. This environment variable is used regardless of which language is being preprocessed.

The remaining environment variables apply only when preprocessing the particular language indicated. Each specifies a list of directories to be searched as if specified with -isystem, but after any paths given with -isystem options on the command line.

In all these variables, an empty element instructs the compiler to search its current working directory. Empty elements can appear at the beginning or end of a path. For instance, if the value of CPATH is :/special/include, that has the same effect as '-I. -I/special/include'.

I think that most setups avoid using the environment variables and instead pass the include directories in the command line using the -I option. there will usually be a makefile variable or an IDE setting to control what gets passed to -I.

like image 109
Michael Burr Avatar answered Sep 17 '22 13:09

Michael Burr


Just look at the actual gcc documentation. It's all explained there.

To summarize:

  • LIBRARY_PATH is for the linker, not for header files (used when looking for libraries requested by a -l option)
  • CPATH specifies directories to look for header files in (like the -I option)
  • C_INCLUDE_PATH and CPLUS_INCLUDE_PATH are like CPATH, but for C/C++ respectively.
like image 26
Cascabel Avatar answered Sep 18 '22 13:09

Cascabel