summaryrefslogtreecommitdiff
path: root/devdocs/gcc~13/environment-variables.html
blob: b23a76b460bc60686c98fa013f28951b6cdbf033 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<div class="section-level-extent" id="Environment-Variables"> <div class="nav-panel"> <p> Next: <a href="precompiled-headers" accesskey="n" rel="next">Using Precompiled Headers</a>, Previous: <a href="spec-files" accesskey="p" rel="prev">Specifying Subprocesses and the Switches to Pass to Them</a>, Up: <a href="invoking-gcc" accesskey="u" rel="up">GCC Command Options</a> [<a href="index#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="indices" title="Index" rel="index">Index</a>]</p> </div>  <h1 class="section" id="Environment-Variables-Affecting-GCC"><span>3.21 Environment Variables Affecting GCC<a class="copiable-link" href="#Environment-Variables-Affecting-GCC"> ¶</a></span></h1>  <p>This section describes several environment variables that affect how GCC operates. Some of them work by specifying directories or prefixes to use when searching for various kinds of files. Some are used to specify other aspects of the compilation environment. </p> <p>Note that you can also specify places to search using options such as <samp class="option">-B</samp>, <samp class="option">-I</samp> and <samp class="option">-L</samp> (see <a class="pxref" href="directory-options">Options for Directory Search</a>). These take precedence over places specified using environment variables, which in turn take precedence over those specified by the configuration of GCC. See <a data-manual="gccint" href="https://gcc.gnu.org/onlinedocs/gccint/Driver.html#Driver">Controlling the Compilation Driver <samp class="file">gcc</samp></a> in GNU Compiler Collection (GCC) Internals. </p> <dl class="table"> <dt>
    <span><code class="env">LANG</code><a class="copiable-link" href="#index-LANG"> ¶</a></span>
</dt> <dt><code class="env">LC_CTYPE</code></dt> <dt><code class="env">LC_MESSAGES</code></dt> <dt><code class="env">LC_ALL</code></dt> <dd>
<p>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 <code class="env">LC_CTYPE</code> and <code class="env">LC_MESSAGES</code> if it has been configured to do so. These locale categories can be set to any value supported by your installation. A typical value is ‘<samp class="samp">en_GB.UTF-8</samp>’ for English in the United Kingdom encoded in UTF-8. </p> <p>The <code class="env">LC_CTYPE</code> environment variable specifies character classification. GCC uses it to determine the character boundaries in a string; this is needed for some multibyte encodings that contain quote and escape characters that are otherwise interpreted as a string end or escape. </p> <p>The <code class="env">LC_MESSAGES</code> environment variable specifies the language to use in diagnostic messages. </p> <p>If the <code class="env">LC_ALL</code> environment variable is set, it overrides the value of <code class="env">LC_CTYPE</code> and <code class="env">LC_MESSAGES</code>; otherwise, <code class="env">LC_CTYPE</code> and <code class="env">LC_MESSAGES</code> default to the value of the <code class="env">LANG</code> environment variable. If none of these variables are set, GCC defaults to traditional C English behavior. </p> </dd> <dt>
<span><code class="env">TMPDIR</code><a class="copiable-link" href="#index-TMPDIR"> ¶</a></span>
</dt> <dd>
<p>If <code class="env">TMPDIR</code> is set, it specifies the directory to use for temporary files. GCC uses temporary files to hold the output of one stage of compilation which is to be used as input to the next stage: for example, the output of the preprocessor, which is the input to the compiler proper. </p> </dd> <dt>
<span><code class="env">GCC_COMPARE_DEBUG</code><a class="copiable-link" href="#index-GCC_005fCOMPARE_005fDEBUG"> ¶</a></span>
</dt> <dd>
<p>Setting <code class="env">GCC_COMPARE_DEBUG</code> is nearly equivalent to passing <samp class="option">-fcompare-debug</samp> to the compiler driver. See the documentation of this option for more details. </p> </dd> <dt>
<span><code class="env">GCC_EXEC_PREFIX</code><a class="copiable-link" href="#index-GCC_005fEXEC_005fPREFIX"> ¶</a></span>
</dt> <dd>
<p>If <code class="env">GCC_EXEC_PREFIX</code> is set, it specifies a prefix to use in the names of the subprograms executed by the compiler. No slash is added when this prefix is combined with the name of a subprogram, but you can specify a prefix that ends with a slash if you wish. </p> <p>If <code class="env">GCC_EXEC_PREFIX</code> is not set, GCC attempts to figure out an appropriate prefix to use based on the pathname it is invoked with. </p> <p>If GCC cannot find the subprogram using the specified prefix, it tries looking in the usual places for the subprogram. </p> <p>The default value of <code class="env">GCC_EXEC_PREFIX</code> is <samp class="file"><var class="var">prefix</var>/lib/gcc/</samp> where <var class="var">prefix</var> is the prefix to the installed compiler. In many cases <var class="var">prefix</var> is the value of <code class="code">prefix</code> when you ran the <samp class="file">configure</samp> script. </p> <p>Other prefixes specified with <samp class="option">-B</samp> take precedence over this prefix. </p> <p>This prefix is also used for finding files such as <samp class="file">crt0.o</samp> that are used for linking. </p> <p>In addition, the prefix is used in an unusual way in finding the directories to search for header files. For each of the standard directories whose name normally begins with ‘<samp class="samp">/usr/local/lib/gcc</samp>’ (more precisely, with the value of <code class="env">GCC_INCLUDE_DIR</code>), GCC tries replacing that beginning with the specified prefix to produce an alternate directory name. Thus, with <samp class="option">-Bfoo/</samp>, GCC searches <samp class="file">foo/bar</samp> just before it searches the standard directory <samp class="file">/usr/local/lib/bar</samp>. If a standard directory begins with the configured <var class="var">prefix</var> then the value of <var class="var">prefix</var> is replaced by <code class="env">GCC_EXEC_PREFIX</code> when looking for header files. </p> </dd> <dt>
<span><code class="env">COMPILER_PATH</code><a class="copiable-link" href="#index-COMPILER_005fPATH"> ¶</a></span>
</dt> <dd>
<p>The value of <code class="env">COMPILER_PATH</code> is a colon-separated list of directories, much like <code class="env">PATH</code>. GCC tries the directories thus specified when searching for subprograms, if it cannot find the subprograms using <code class="env">GCC_EXEC_PREFIX</code>. </p> </dd> <dt>
<span><code class="env">LIBRARY_PATH</code><a class="copiable-link" href="#index-LIBRARY_005fPATH"> ¶</a></span>
</dt> <dd>
<p>The value of <code class="env">LIBRARY_PATH</code> is a colon-separated list of directories, much like <code class="env">PATH</code>. When configured as a native compiler, GCC tries the directories thus specified when searching for special linker files, if it cannot find them using <code class="env">GCC_EXEC_PREFIX</code>. Linking using GCC also uses these directories when searching for ordinary libraries for the <samp class="option">-l</samp> option (but directories specified with <samp class="option">-L</samp> come first). </p> </dd> <dt>
 <span><code class="env">LANG</code><a class="copiable-link" href="#index-LANG-1"> ¶</a></span>
</dt> <dd>
<p>This variable is used to pass locale information to the compiler. One way in which this information is used is to determine the character set to be used when character literals, string literals and comments are parsed in C and C++. When the compiler is configured to allow multibyte characters, the following values for <code class="env">LANG</code> are recognized: </p> <dl class="table"> <dt>‘<samp class="samp">C-JIS</samp>’</dt> <dd><p>Recognize JIS characters. </p></dd> <dt>‘<samp class="samp">C-SJIS</samp>’</dt> <dd><p>Recognize SJIS characters. </p></dd> <dt>‘<samp class="samp">C-EUCJP</samp>’</dt> <dd><p>Recognize EUCJP characters. </p></dd> </dl> <p>If <code class="env">LANG</code> is not defined, or if it has some other value, then the compiler uses <code class="code">mblen</code> and <code class="code">mbtowc</code> as defined by the default locale to recognize and translate multibyte characters. </p> </dd> <dt>
<span><code class="env">GCC_EXTRA_DIAGNOSTIC_OUTPUT</code><a class="copiable-link" href="#index-GCC_005fEXTRA_005fDIAGNOSTIC_005fOUTPUT"> ¶</a></span>
</dt> <dd>
<p>If <code class="env">GCC_EXTRA_DIAGNOSTIC_OUTPUT</code> is set to one of the following values, then additional text will be emitted to stderr when fix-it hints are emitted. <samp class="option">-fdiagnostics-parseable-fixits</samp> and <samp class="option">-fno-diagnostics-parseable-fixits</samp> take precedence over this environment variable. </p> <dl class="table"> <dt>‘<samp class="samp">fixits-v1</samp>’</dt> <dd>
<p>Emit parseable fix-it hints, equivalent to <samp class="option">-fdiagnostics-parseable-fixits</samp>. In particular, columns are expressed as a count of bytes, starting at byte 1 for the initial column. </p> </dd> <dt>‘<samp class="samp">fixits-v2</samp>’</dt> <dd><p>As <code class="code">fixits-v1</code>, but columns are expressed as display columns, as per <samp class="option">-fdiagnostics-column-unit=display</samp>. </p></dd> </dl> </dd> </dl> <p>Some additional environment variables affect the behavior of the preprocessor. </p> <dl class="vtable"> <dt>
<span><code class="env">CPATH</code><a class="copiable-link" href="#index-CPATH"> ¶</a></span>
</dt> <dt>
<span><code class="env">C_INCLUDE_PATH</code><a class="copiable-link" href="#index-C_005fINCLUDE_005fPATH"> ¶</a></span>
</dt> <dt>
<span><code class="env">CPLUS_INCLUDE_PATH</code><a class="copiable-link" href="#index-CPLUS_005fINCLUDE_005fPATH"> ¶</a></span>
</dt> <dt>
<span><code class="env">OBJC_INCLUDE_PATH</code><a class="copiable-link" href="#index-OBJC_005fINCLUDE_005fPATH"> ¶</a></span>
</dt> <dd>
<p>Each variable’s value is a list of directories separated by a special character, much like <code class="env">PATH</code>, in which to look for header files. The special character, <code class="code">PATH_SEPARATOR</code>, 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. </p> <p><code class="env">CPATH</code> specifies a list of directories to be searched as if specified with <samp class="option">-I</samp>, but after any paths given with <samp class="option">-I</samp> options on the command line. This environment variable is used regardless of which language is being preprocessed. </p> <p>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 <samp class="option">-isystem</samp>, but after any paths given with <samp class="option">-isystem</samp> options on the command line. </p> <p>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 <code class="env">CPATH</code> is <code class="code">:/special/include</code>, that has the same effect as ‘<samp class="samp">-I. -I/special/include</samp>’. </p> </dd> <dt>
 <span><code class="env">DEPENDENCIES_OUTPUT</code><a class="copiable-link" href="#index-DEPENDENCIES_005fOUTPUT"> ¶</a></span>
</dt> <dd>
<p>If this variable is set, its value specifies how to output dependencies for Make based on the non-system header files processed by the compiler. System header files are ignored in the dependency output. </p> <p>The value of <code class="env">DEPENDENCIES_OUTPUT</code> can be just a file name, in which case the Make rules are written to that file, guessing the target name from the source file name. Or the value can have the form ‘<samp class="samp"><var class="var">file</var> <var class="var">target</var></samp>’, in which case the rules are written to file <var class="var">file</var> using <var class="var">target</var> as the target name. </p> <p>In other words, this environment variable is equivalent to combining the options <samp class="option">-MM</samp> and <samp class="option">-MF</samp> (see <a class="pxref" href="preprocessor-options">Options Controlling the Preprocessor</a>), with an optional <samp class="option">-MT</samp> switch too. </p> </dd> <dt>
 <span><code class="env">SUNPRO_DEPENDENCIES</code><a class="copiable-link" href="#index-SUNPRO_005fDEPENDENCIES"> ¶</a></span>
</dt> <dd>
<p>This variable is the same as <code class="env">DEPENDENCIES_OUTPUT</code> (see above), except that system header files are not ignored, so it implies <samp class="option">-M</samp> rather than <samp class="option">-MM</samp>. However, the dependence on the main input file is omitted. See <a class="xref" href="preprocessor-options">Options Controlling the Preprocessor</a>. </p> </dd> <dt>
<span><code class="env">SOURCE_DATE_EPOCH</code><a class="copiable-link" href="#index-SOURCE_005fDATE_005fEPOCH"> ¶</a></span>
</dt> <dd>
<p>If this variable is set, its value specifies a UNIX timestamp to be used in replacement of the current date and time in the <code class="code">__DATE__</code> and <code class="code">__TIME__</code> macros, so that the embedded timestamps become reproducible. </p> <p>The value of <code class="env">SOURCE_DATE_EPOCH</code> must be a UNIX timestamp, defined as the number of seconds (excluding leap seconds) since 01 Jan 1970 00:00:00 represented in ASCII; identical to the output of <code class="code">date +%s</code> on GNU/Linux and other systems that support the <code class="code">%s</code> extension in the <code class="code">date</code> command. </p> <p>The value should be a known timestamp such as the last modification time of the source or package and it should be set by the build process. </p> </dd> </dl> </div>  <div class="nav-panel"> <p> Next: <a href="precompiled-headers">Using Precompiled Headers</a>, Previous: <a href="spec-files">Specifying Subprocesses and the Switches to Pass to Them</a>, Up: <a href="invoking-gcc">GCC Command Options</a> [<a href="index#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="indices" title="Index" rel="index">Index</a>]</p> </div><div class="_attribution">
  <p class="_attribution-p">
    &copy; Free Software Foundation<br>Licensed under the GNU Free Documentation License, Version 1.3.<br>
    <a href="https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Environment-Variables.html" class="_attribution-link">https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Environment-Variables.html</a>
  </p>
</div>