Environment-Variables.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2017 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <title>Using the GNU Compiler Collection (GCC): Environment Variables</title>
  20. <meta name="description" content="Using the GNU Compiler Collection (GCC): Environment Variables">
  21. <meta name="keywords" content="Using the GNU Compiler Collection (GCC): Environment Variables">
  22. <meta name="resource-type" content="document">
  23. <meta name="distribution" content="global">
  24. <meta name="Generator" content="makeinfo">
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Invoking-GCC.html#Invoking-GCC" rel="up" title="Invoking GCC">
  30. <link href="Precompiled-Headers.html#Precompiled-Headers" rel="next" title="Precompiled Headers">
  31. <link href="Spec-Files.html#Spec-Files" rel="prev" title="Spec Files">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.smallquotation {font-size: smaller}
  36. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.indentedblock {margin-left: 3.2em}
  39. div.lisp {margin-left: 3.2em}
  40. div.smalldisplay {margin-left: 3.2em}
  41. div.smallexample {margin-left: 3.2em}
  42. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style:oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nocodebreak {white-space:nowrap}
  54. span.nolinebreak {white-space:nowrap}
  55. span.roman {font-family:serif; font-weight:normal}
  56. span.sansserif {font-family:sans-serif; font-weight:normal}
  57. ul.no-bullet {list-style: none}
  58. -->
  59. </style>
  60. </head>
  61. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  62. <a name="Environment-Variables"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Precompiled-Headers.html#Precompiled-Headers" accesskey="n" rel="next">Precompiled Headers</a>, Previous: <a href="Spec-Files.html#Spec-Files" accesskey="p" rel="prev">Spec Files</a>, Up: <a href="Invoking-GCC.html#Invoking-GCC" accesskey="u" rel="up">Invoking GCC</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  66. </div>
  67. <hr>
  68. <a name="Environment-Variables-Affecting-GCC"></a>
  69. <h3 class="section">3.20 Environment Variables Affecting GCC</h3>
  70. <a name="index-environment-variables"></a>
  71. <p>This section describes several environment variables that affect how GCC
  72. operates. Some of them work by specifying directories or prefixes to use
  73. when searching for various kinds of files. Some are used to specify other
  74. aspects of the compilation environment.
  75. </p>
  76. <p>Note that you can also specify places to search using options such as
  77. <samp>-B</samp>, <samp>-I</samp> and <samp>-L</samp> (see <a href="Directory-Options.html#Directory-Options">Directory Options</a>). These
  78. take precedence over places specified using environment variables, which
  79. in turn take precedence over those specified by the configuration of GCC.
  80. See <a href="http://gcc.gnu.org/onlinedocs/gccint/Driver.html#Driver">Controlling the Compilation Driver <samp>gcc</samp></a> in <cite>GNU Compiler Collection (GCC) Internals</cite>.
  81. </p>
  82. <dl compact="compact">
  83. <dt><code>LANG</code></dt>
  84. <dt><code>LC_CTYPE</code></dt>
  85. <dt><code>LC_MESSAGES</code></dt>
  86. <dt><code>LC_ALL</code></dt>
  87. <dd><a name="index-LANG"></a>
  88. <a name="index-LC_005fCTYPE"></a>
  89. <a name="index-LC_005fMESSAGES"></a>
  90. <a name="index-LC_005fALL"></a>
  91. <a name="index-locale"></a>
  92. <p>These environment variables control the way that GCC uses
  93. localization information which allows GCC to work with different
  94. national conventions. GCC inspects the locale categories
  95. <code>LC_CTYPE</code> and <code>LC_MESSAGES</code> if it has been configured to do
  96. so. These locale categories can be set to any value supported by your
  97. installation. A typical value is &lsquo;<samp>en_GB.UTF-8</samp>&rsquo; for English in the United
  98. Kingdom encoded in UTF-8.
  99. </p>
  100. <p>The <code>LC_CTYPE</code> environment variable specifies character
  101. classification. GCC uses it to determine the character boundaries in
  102. a string; this is needed for some multibyte encodings that contain quote
  103. and escape characters that are otherwise interpreted as a string
  104. end or escape.
  105. </p>
  106. <p>The <code>LC_MESSAGES</code> environment variable specifies the language to
  107. use in diagnostic messages.
  108. </p>
  109. <p>If the <code>LC_ALL</code> environment variable is set, it overrides the value
  110. of <code>LC_CTYPE</code> and <code>LC_MESSAGES</code>; otherwise, <code>LC_CTYPE</code>
  111. and <code>LC_MESSAGES</code> default to the value of the <code>LANG</code>
  112. environment variable. If none of these variables are set, GCC
  113. defaults to traditional C English behavior.
  114. </p>
  115. </dd>
  116. <dt><code>TMPDIR</code></dt>
  117. <dd><a name="index-TMPDIR"></a>
  118. <p>If <code>TMPDIR</code> is set, it specifies the directory to use for temporary
  119. files. GCC uses temporary files to hold the output of one stage of
  120. compilation which is to be used as input to the next stage: for example,
  121. the output of the preprocessor, which is the input to the compiler
  122. proper.
  123. </p>
  124. </dd>
  125. <dt><code>GCC_COMPARE_DEBUG</code></dt>
  126. <dd><a name="index-GCC_005fCOMPARE_005fDEBUG"></a>
  127. <p>Setting <code>GCC_COMPARE_DEBUG</code> is nearly equivalent to passing
  128. <samp>-fcompare-debug</samp> to the compiler driver. See the documentation
  129. of this option for more details.
  130. </p>
  131. </dd>
  132. <dt><code>GCC_EXEC_PREFIX</code></dt>
  133. <dd><a name="index-GCC_005fEXEC_005fPREFIX"></a>
  134. <p>If <code>GCC_EXEC_PREFIX</code> is set, it specifies a prefix to use in the
  135. names of the subprograms executed by the compiler. No slash is added
  136. when this prefix is combined with the name of a subprogram, but you can
  137. specify a prefix that ends with a slash if you wish.
  138. </p>
  139. <p>If <code>GCC_EXEC_PREFIX</code> is not set, GCC attempts to figure out
  140. an appropriate prefix to use based on the pathname it is invoked with.
  141. </p>
  142. <p>If GCC cannot find the subprogram using the specified prefix, it
  143. tries looking in the usual places for the subprogram.
  144. </p>
  145. <p>The default value of <code>GCC_EXEC_PREFIX</code> is
  146. <samp><var>prefix</var>/lib/gcc/</samp> where <var>prefix</var> is the prefix to
  147. the installed compiler. In many cases <var>prefix</var> is the value
  148. of <code>prefix</code> when you ran the <samp>configure</samp> script.
  149. </p>
  150. <p>Other prefixes specified with <samp>-B</samp> take precedence over this prefix.
  151. </p>
  152. <p>This prefix is also used for finding files such as <samp>crt0.o</samp> that are
  153. used for linking.
  154. </p>
  155. <p>In addition, the prefix is used in an unusual way in finding the
  156. directories to search for header files. For each of the standard
  157. directories whose name normally begins with &lsquo;<samp>/usr/local/lib/gcc</samp>&rsquo;
  158. (more precisely, with the value of <code>GCC_INCLUDE_DIR</code>), GCC tries
  159. replacing that beginning with the specified prefix to produce an
  160. alternate directory name. Thus, with <samp>-Bfoo/</samp>, GCC searches
  161. <samp>foo/bar</samp> just before it searches the standard directory
  162. <samp>/usr/local/lib/bar</samp>.
  163. If a standard directory begins with the configured
  164. <var>prefix</var> then the value of <var>prefix</var> is replaced by
  165. <code>GCC_EXEC_PREFIX</code> when looking for header files.
  166. </p>
  167. </dd>
  168. <dt><code>COMPILER_PATH</code></dt>
  169. <dd><a name="index-COMPILER_005fPATH"></a>
  170. <p>The value of <code>COMPILER_PATH</code> is a colon-separated list of
  171. directories, much like <code>PATH</code>. GCC tries the directories thus
  172. specified when searching for subprograms, if it cannot find the
  173. subprograms using <code>GCC_EXEC_PREFIX</code>.
  174. </p>
  175. </dd>
  176. <dt><code>LIBRARY_PATH</code></dt>
  177. <dd><a name="index-LIBRARY_005fPATH"></a>
  178. <p>The value of <code>LIBRARY_PATH</code> is a colon-separated list of
  179. directories, much like <code>PATH</code>. When configured as a native compiler,
  180. GCC tries the directories thus specified when searching for special
  181. linker files, if it cannot find them using <code>GCC_EXEC_PREFIX</code>. Linking
  182. using GCC also uses these directories when searching for ordinary
  183. libraries for the <samp>-l</samp> option (but directories specified with
  184. <samp>-L</samp> come first).
  185. </p>
  186. </dd>
  187. <dt><code>LANG</code></dt>
  188. <dd><a name="index-LANG-1"></a>
  189. <a name="index-locale-definition"></a>
  190. <p>This variable is used to pass locale information to the compiler. One way in
  191. which this information is used is to determine the character set to be used
  192. when character literals, string literals and comments are parsed in C and C++.
  193. When the compiler is configured to allow multibyte characters,
  194. the following values for <code>LANG</code> are recognized:
  195. </p>
  196. <dl compact="compact">
  197. <dt>&lsquo;<samp>C-JIS</samp>&rsquo;</dt>
  198. <dd><p>Recognize JIS characters.
  199. </p></dd>
  200. <dt>&lsquo;<samp>C-SJIS</samp>&rsquo;</dt>
  201. <dd><p>Recognize SJIS characters.
  202. </p></dd>
  203. <dt>&lsquo;<samp>C-EUCJP</samp>&rsquo;</dt>
  204. <dd><p>Recognize EUCJP characters.
  205. </p></dd>
  206. </dl>
  207. <p>If <code>LANG</code> is not defined, or if it has some other value, then the
  208. compiler uses <code>mblen</code> and <code>mbtowc</code> as defined by the default locale to
  209. recognize and translate multibyte characters.
  210. </p></dd>
  211. </dl>
  212. <p>Some additional environment variables affect the behavior of the
  213. preprocessor.
  214. </p>
  215. <dl compact="compact">
  216. <dt><code>CPATH</code>
  217. <a name="index-CPATH"></a>
  218. </dt>
  219. <dt><code>C_INCLUDE_PATH</code>
  220. <a name="index-C_005fINCLUDE_005fPATH"></a>
  221. </dt>
  222. <dt><code>CPLUS_INCLUDE_PATH</code>
  223. <a name="index-CPLUS_005fINCLUDE_005fPATH"></a>
  224. </dt>
  225. <dt><code>OBJC_INCLUDE_PATH</code>
  226. <a name="index-OBJC_005fINCLUDE_005fPATH"></a>
  227. </dt>
  228. <dd><p>Each variable&rsquo;s value is a list of directories separated by a special
  229. character, much like <code>PATH</code>, in which to look for header files.
  230. The special character, <code>PATH_SEPARATOR</code>, is target-dependent and
  231. determined at GCC build time. For Microsoft Windows-based targets it is a
  232. semicolon, and for almost all other targets it is a colon.
  233. </p>
  234. <p><code>CPATH</code> specifies a list of directories to be searched as if
  235. specified with <samp>-I</samp>, but after any paths given with <samp>-I</samp>
  236. options on the command line. This environment variable is used
  237. regardless of which language is being preprocessed.
  238. </p>
  239. <p>The remaining environment variables apply only when preprocessing the
  240. particular language indicated. Each specifies a list of directories
  241. to be searched as if specified with <samp>-isystem</samp>, but after any
  242. paths given with <samp>-isystem</samp> options on the command line.
  243. </p>
  244. <p>In all these variables, an empty element instructs the compiler to
  245. search its current working directory. Empty elements can appear at the
  246. beginning or end of a path. For instance, if the value of
  247. <code>CPATH</code> is <code>:/special/include</code>, that has the same
  248. effect as &lsquo;<samp><span class="nolinebreak">-I.</span>&nbsp;<span class="nolinebreak">-I/special/include</span><!-- /@w --></samp>&rsquo;.
  249. </p>
  250. </dd>
  251. <dt><code>DEPENDENCIES_OUTPUT</code>
  252. <a name="index-DEPENDENCIES_005fOUTPUT"></a>
  253. </dt>
  254. <dd><a name="index-dependencies-for-make-as-output"></a>
  255. <p>If this variable is set, its value specifies how to output
  256. dependencies for Make based on the non-system header files processed
  257. by the compiler. System header files are ignored in the dependency
  258. output.
  259. </p>
  260. <p>The value of <code>DEPENDENCIES_OUTPUT</code> can be just a file name, in
  261. which case the Make rules are written to that file, guessing the target
  262. name from the source file name. Or the value can have the form
  263. &lsquo;<samp><var>file</var> <var>target</var></samp>&rsquo;, in which case the rules are written to
  264. file <var>file</var> using <var>target</var> as the target name.
  265. </p>
  266. <p>In other words, this environment variable is equivalent to combining
  267. the options <samp>-MM</samp> and <samp>-MF</samp>
  268. (see <a href="Preprocessor-Options.html#Preprocessor-Options">Preprocessor Options</a>),
  269. with an optional <samp>-MT</samp> switch too.
  270. </p>
  271. </dd>
  272. <dt><code>SUNPRO_DEPENDENCIES</code>
  273. <a name="index-SUNPRO_005fDEPENDENCIES"></a>
  274. </dt>
  275. <dd><a name="index-dependencies-for-make-as-output-1"></a>
  276. <p>This variable is the same as <code>DEPENDENCIES_OUTPUT</code> (see above),
  277. except that system header files are not ignored, so it implies
  278. <samp>-M</samp> rather than <samp>-MM</samp>. However, the dependence on the
  279. main input file is omitted.
  280. See <a href="Preprocessor-Options.html#Preprocessor-Options">Preprocessor Options</a>.
  281. </p>
  282. </dd>
  283. <dt><code>SOURCE_DATE_EPOCH</code>
  284. <a name="index-SOURCE_005fDATE_005fEPOCH"></a>
  285. </dt>
  286. <dd><p>If this variable is set, its value specifies a UNIX timestamp to be
  287. used in replacement of the current date and time in the <code>__DATE__</code>
  288. and <code>__TIME__</code> macros, so that the embedded timestamps become
  289. reproducible.
  290. </p>
  291. <p>The value of <code>SOURCE_DATE_EPOCH</code> must be a UNIX timestamp,
  292. defined as the number of seconds (excluding leap seconds) since
  293. 01 Jan 1970 00:00:00 represented in ASCII; identical to the output of
  294. &lsquo;<samp><code>date +%s</code></samp>&rsquo; on GNU/Linux and other systems that support the
  295. <code>%s</code> extension in the <code>date</code> command.
  296. </p>
  297. <p>The value should be a known timestamp such as the last modification
  298. time of the source or package and it should be set by the build
  299. process.
  300. </p>
  301. </dd>
  302. </dl>
  303. <hr>
  304. <div class="header">
  305. <p>
  306. Next: <a href="Precompiled-Headers.html#Precompiled-Headers" accesskey="n" rel="next">Precompiled Headers</a>, Previous: <a href="Spec-Files.html#Spec-Files" accesskey="p" rel="prev">Spec Files</a>, Up: <a href="Invoking-GCC.html#Invoking-GCC" accesskey="u" rel="up">Invoking GCC</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  307. </div>
  308. </body>
  309. </html>