Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

533 rindas
25KB

  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-2020 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 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>Link Options (Using the GNU Compiler Collection (GCC))</title>
  21. <meta name="description" content="Link Options (Using the GNU Compiler Collection (GCC))">
  22. <meta name="keywords" content="Link Options (Using the GNU Compiler Collection (GCC))">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  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="Directory-Options.html#Directory-Options" rel="next" title="Directory Options">
  31. <link href="Assembler-Options.html#Assembler-Options" rel="prev" title="Assembler Options">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  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.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="Link-Options"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Directory-Options.html#Directory-Options" accesskey="n" rel="next">Directory Options</a>, Previous: <a href="Assembler-Options.html#Assembler-Options" accesskey="p" rel="prev">Assembler Options</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>
  65. </div>
  66. <hr>
  67. <a name="Options-for-Linking"></a>
  68. <h3 class="section">3.15 Options for Linking</h3>
  69. <a name="index-link-options"></a>
  70. <a name="index-options_002c-linking"></a>
  71. <p>These options come into play when the compiler links object files into
  72. an executable output file. They are meaningless if the compiler is
  73. not doing a link step.
  74. </p>
  75. <dl compact="compact">
  76. <dd><a name="index-file-names"></a>
  77. </dd>
  78. <dt><code><var>object-file-name</var></code></dt>
  79. <dd><p>A file name that does not end in a special recognized suffix is
  80. considered to name an object file or library. (Object files are
  81. distinguished from libraries by the linker according to the file
  82. contents.) If linking is done, these object files are used as input
  83. to the linker.
  84. </p>
  85. </dd>
  86. <dt><code>-c</code></dt>
  87. <dt><code>-S</code></dt>
  88. <dt><code>-E</code></dt>
  89. <dd><a name="index-c-1"></a>
  90. <a name="index-S-1"></a>
  91. <a name="index-E-1"></a>
  92. <p>If any of these options is used, then the linker is not run, and
  93. object file names should not be used as arguments. See <a href="Overall-Options.html#Overall-Options">Overall Options</a>.
  94. </p>
  95. </dd>
  96. <dt><code>-flinker-output=<var>type</var></code></dt>
  97. <dd><a name="index-flinker_002doutput"></a>
  98. <p>This option controls code generation of the link-time optimizer. By
  99. default the linker output is automatically determined by the linker
  100. plugin. For debugging the compiler and if incremental linking with a
  101. non-LTO object file is desired, it may be useful to control the type
  102. manually.
  103. </p>
  104. <p>If <var>type</var> is &lsquo;<samp>exec</samp>&rsquo;, code generation produces a static
  105. binary. In this case <samp>-fpic</samp> and <samp>-fpie</samp> are both
  106. disabled.
  107. </p>
  108. <p>If <var>type</var> is &lsquo;<samp>dyn</samp>&rsquo;, code generation produces a shared
  109. library. In this case <samp>-fpic</samp> or <samp>-fPIC</samp> is preserved,
  110. but not enabled automatically. This allows to build shared libraries
  111. without position-independent code on architectures where this is
  112. possible, i.e. on x86.
  113. </p>
  114. <p>If <var>type</var> is &lsquo;<samp>pie</samp>&rsquo;, code generation produces an <samp>-fpie</samp>
  115. executable. This results in similar optimizations as &lsquo;<samp>exec</samp>&rsquo;
  116. except that <samp>-fpie</samp> is not disabled if specified at compilation
  117. time.
  118. </p>
  119. <p>If <var>type</var> is &lsquo;<samp>rel</samp>&rsquo;, the compiler assumes that incremental linking is
  120. done. The sections containing intermediate code for link-time optimization are
  121. merged, pre-optimized, and output to the resulting object file. In addition, if
  122. <samp>-ffat-lto-objects</samp> is specified, binary code is produced for future
  123. non-LTO linking. The object file produced by incremental linking is smaller
  124. than a static library produced from the same object files. At link time the
  125. result of incremental linking also loads faster than a static
  126. library assuming that the majority of objects in the library are used.
  127. </p>
  128. <p>Finally &lsquo;<samp>nolto-rel</samp>&rsquo; configures the compiler for incremental linking where
  129. code generation is forced, a final binary is produced, and the intermediate
  130. code for later link-time optimization is stripped. When multiple object files
  131. are linked together the resulting code is better optimized than with
  132. link-time optimizations disabled (for example, cross-module inlining
  133. happens), but most of benefits of whole program optimizations are lost.
  134. </p>
  135. <p>During the incremental link (by <samp>-r</samp>) the linker plugin defaults to
  136. <samp>rel</samp>. With current interfaces to GNU Binutils it is however not
  137. possible to incrementally link LTO objects and non-LTO objects into a single
  138. mixed object file. If any of object files in incremental link cannot
  139. be used for link-time optimization, the linker plugin issues a warning and
  140. uses &lsquo;<samp>nolto-rel</samp>&rsquo;. To maintain whole program optimization, it is
  141. recommended to link such objects into static library instead. Alternatively it
  142. is possible to use H.J. Lu&rsquo;s binutils with support for mixed objects.
  143. </p>
  144. </dd>
  145. <dt><code>-fuse-ld=bfd</code></dt>
  146. <dd><a name="index-fuse_002dld_003dbfd"></a>
  147. <p>Use the <code>bfd</code> linker instead of the default linker.
  148. </p>
  149. </dd>
  150. <dt><code>-fuse-ld=gold</code></dt>
  151. <dd><a name="index-fuse_002dld_003dgold"></a>
  152. <p>Use the <code>gold</code> linker instead of the default linker.
  153. </p>
  154. </dd>
  155. <dt><code>-fuse-ld=lld</code></dt>
  156. <dd><a name="index-fuse_002dld_003dlld"></a>
  157. <p>Use the LLVM <code>lld</code> linker instead of the default linker.
  158. </p>
  159. <a name="index-Libraries"></a>
  160. </dd>
  161. <dt><code>-l<var>library</var></code></dt>
  162. <dt><code>-l <var>library</var></code></dt>
  163. <dd><a name="index-l"></a>
  164. <p>Search the library named <var>library</var> when linking. (The second
  165. alternative with the library as a separate argument is only for
  166. POSIX compliance and is not recommended.)
  167. </p>
  168. <p>The <samp>-l</samp> option is passed directly to the linker by GCC. Refer
  169. to your linker documentation for exact details. The general
  170. description below applies to the GNU linker.
  171. </p>
  172. <p>The linker searches a standard list of directories for the library.
  173. The directories searched include several standard system directories
  174. plus any that you specify with <samp>-L</samp>.
  175. </p>
  176. <p>Static libraries are archives of object files, and have file names
  177. like <samp>lib<var>library</var>.a</samp>. Some targets also support shared
  178. libraries, which typically have names like <samp>lib<var>library</var>.so</samp>.
  179. If both static and shared libraries are found, the linker gives
  180. preference to linking with the shared library unless the
  181. <samp>-static</samp> option is used.
  182. </p>
  183. <p>It makes a difference where in the command you write this option; the
  184. linker searches and processes libraries and object files in the order they
  185. are specified. Thus, &lsquo;<samp>foo.o -lz bar.o</samp>&rsquo; searches library &lsquo;<samp>z</samp>&rsquo;
  186. after file <samp>foo.o</samp> but before <samp>bar.o</samp>. If <samp>bar.o</samp> refers
  187. to functions in &lsquo;<samp>z</samp>&rsquo;, those functions may not be loaded.
  188. </p>
  189. </dd>
  190. <dt><code>-lobjc</code></dt>
  191. <dd><a name="index-lobjc"></a>
  192. <p>You need this special case of the <samp>-l</samp> option in order to
  193. link an Objective-C or Objective-C++ program.
  194. </p>
  195. </dd>
  196. <dt><code>-nostartfiles</code></dt>
  197. <dd><a name="index-nostartfiles"></a>
  198. <p>Do not use the standard system startup files when linking.
  199. The standard system libraries are used normally, unless <samp>-nostdlib</samp>,
  200. <samp>-nolibc</samp>, or <samp>-nodefaultlibs</samp> is used.
  201. </p>
  202. </dd>
  203. <dt><code>-nodefaultlibs</code></dt>
  204. <dd><a name="index-nodefaultlibs"></a>
  205. <p>Do not use the standard system libraries when linking.
  206. Only the libraries you specify are passed to the linker, and options
  207. specifying linkage of the system libraries, such as <samp>-static-libgcc</samp>
  208. or <samp>-shared-libgcc</samp>, are ignored.
  209. The standard startup files are used normally, unless <samp>-nostartfiles</samp>
  210. is used.
  211. </p>
  212. <p>The compiler may generate calls to <code>memcmp</code>,
  213. <code>memset</code>, <code>memcpy</code> and <code>memmove</code>.
  214. These entries are usually resolved by entries in
  215. libc. These entry points should be supplied through some other
  216. mechanism when this option is specified.
  217. </p>
  218. </dd>
  219. <dt><code>-nolibc</code></dt>
  220. <dd><a name="index-nolibc"></a>
  221. <p>Do not use the C library or system libraries tightly coupled with it when
  222. linking. Still link with the startup files, <samp>libgcc</samp> or toolchain
  223. provided language support libraries such as <samp>libgnat</samp>, <samp>libgfortran</samp>
  224. or <samp>libstdc++</samp> unless options preventing their inclusion are used as
  225. well. This typically removes <samp>-lc</samp> from the link command line, as well
  226. as system libraries that normally go with it and become meaningless when
  227. absence of a C library is assumed, for example <samp>-lpthread</samp> or
  228. <samp>-lm</samp> in some configurations. This is intended for bare-board
  229. targets when there is indeed no C library available.
  230. </p>
  231. </dd>
  232. <dt><code>-nostdlib</code></dt>
  233. <dd><a name="index-nostdlib"></a>
  234. <p>Do not use the standard system startup files or libraries when linking.
  235. No startup files and only the libraries you specify are passed to
  236. the linker, and options specifying linkage of the system libraries, such as
  237. <samp>-static-libgcc</samp> or <samp>-shared-libgcc</samp>, are ignored.
  238. </p>
  239. <p>The compiler may generate calls to <code>memcmp</code>, <code>memset</code>,
  240. <code>memcpy</code> and <code>memmove</code>.
  241. These entries are usually resolved by entries in
  242. libc. These entry points should be supplied through some other
  243. mechanism when this option is specified.
  244. </p>
  245. <a name="index-_002dlgcc_002c-use-with-_002dnostdlib"></a>
  246. <a name="index-_002dnostdlib-and-unresolved-references"></a>
  247. <a name="index-unresolved-references-and-_002dnostdlib"></a>
  248. <a name="index-_002dlgcc_002c-use-with-_002dnodefaultlibs"></a>
  249. <a name="index-_002dnodefaultlibs-and-unresolved-references"></a>
  250. <a name="index-unresolved-references-and-_002dnodefaultlibs"></a>
  251. <p>One of the standard libraries bypassed by <samp>-nostdlib</samp> and
  252. <samp>-nodefaultlibs</samp> is <samp>libgcc.a</samp>, a library of internal subroutines
  253. which GCC uses to overcome shortcomings of particular machines, or special
  254. needs for some languages.
  255. (See <a href="http://gcc.gnu.org/onlinedocs/gccint/Interface.html#Interface">Interfacing to GCC Output</a> in <cite>GNU Compiler
  256. Collection (GCC) Internals</cite>,
  257. for more discussion of <samp>libgcc.a</samp>.)
  258. In most cases, you need <samp>libgcc.a</samp> even when you want to avoid
  259. other standard libraries. In other words, when you specify <samp>-nostdlib</samp>
  260. or <samp>-nodefaultlibs</samp> you should usually specify <samp>-lgcc</samp> as well.
  261. This ensures that you have no unresolved references to internal GCC
  262. library subroutines.
  263. (An example of such an internal subroutine is <code>__main</code>, used to ensure C++
  264. constructors are called; see <a href="http://gcc.gnu.org/onlinedocs/gccint/Collect2.html#Collect2"><code>collect2</code></a> in <cite>GNU Compiler Collection (GCC) Internals</cite>.)
  265. </p>
  266. </dd>
  267. <dt><code>-e <var>entry</var></code></dt>
  268. <dt><code>--entry=<var>entry</var></code></dt>
  269. <dd><a name="index-e"></a>
  270. <a name="index-entry"></a>
  271. <p>Specify that the program entry point is <var>entry</var>. The argument is
  272. interpreted by the linker; the GNU linker accepts either a symbol name
  273. or an address.
  274. </p>
  275. </dd>
  276. <dt><code>-pie</code></dt>
  277. <dd><a name="index-pie"></a>
  278. <p>Produce a dynamically linked position independent executable on targets
  279. that support it. For predictable results, you must also specify the same
  280. set of options used for compilation (<samp>-fpie</samp>, <samp>-fPIE</samp>,
  281. or model suboptions) when you specify this linker option.
  282. </p>
  283. </dd>
  284. <dt><code>-no-pie</code></dt>
  285. <dd><a name="index-no_002dpie"></a>
  286. <p>Don&rsquo;t produce a dynamically linked position independent executable.
  287. </p>
  288. </dd>
  289. <dt><code>-static-pie</code></dt>
  290. <dd><a name="index-static_002dpie"></a>
  291. <p>Produce a static position independent executable on targets that support
  292. it. A static position independent executable is similar to a static
  293. executable, but can be loaded at any address without a dynamic linker.
  294. For predictable results, you must also specify the same set of options
  295. used for compilation (<samp>-fpie</samp>, <samp>-fPIE</samp>, or model
  296. suboptions) when you specify this linker option.
  297. </p>
  298. </dd>
  299. <dt><code>-pthread</code></dt>
  300. <dd><a name="index-pthread-1"></a>
  301. <p>Link with the POSIX threads library. This option is supported on
  302. GNU/Linux targets, most other Unix derivatives, and also on
  303. x86 Cygwin and MinGW targets. On some targets this option also sets
  304. flags for the preprocessor, so it should be used consistently for both
  305. compilation and linking.
  306. </p>
  307. </dd>
  308. <dt><code>-r</code></dt>
  309. <dd><a name="index-r"></a>
  310. <p>Produce a relocatable object as output. This is also known as partial
  311. linking.
  312. </p>
  313. </dd>
  314. <dt><code>-rdynamic</code></dt>
  315. <dd><a name="index-rdynamic"></a>
  316. <p>Pass the flag <samp>-export-dynamic</samp> to the ELF linker, on targets
  317. that support it. This instructs the linker to add all symbols, not
  318. only used ones, to the dynamic symbol table. This option is needed
  319. for some uses of <code>dlopen</code> or to allow obtaining backtraces
  320. from within a program.
  321. </p>
  322. </dd>
  323. <dt><code>-s</code></dt>
  324. <dd><a name="index-s"></a>
  325. <p>Remove all symbol table and relocation information from the executable.
  326. </p>
  327. </dd>
  328. <dt><code>-static</code></dt>
  329. <dd><a name="index-static"></a>
  330. <p>On systems that support dynamic linking, this overrides <samp>-pie</samp>
  331. and prevents linking with the shared libraries. On other systems, this
  332. option has no effect.
  333. </p>
  334. </dd>
  335. <dt><code>-shared</code></dt>
  336. <dd><a name="index-shared"></a>
  337. <p>Produce a shared object which can then be linked with other objects to
  338. form an executable. Not all systems support this option. For predictable
  339. results, you must also specify the same set of options used for compilation
  340. (<samp>-fpic</samp>, <samp>-fPIC</samp>, or model suboptions) when
  341. you specify this linker option.<a name="DOCF1" href="#FOOT1"><sup>1</sup></a>
  342. </p>
  343. </dd>
  344. <dt><code>-shared-libgcc</code></dt>
  345. <dt><code>-static-libgcc</code></dt>
  346. <dd><a name="index-shared_002dlibgcc"></a>
  347. <a name="index-static_002dlibgcc"></a>
  348. <p>On systems that provide <samp>libgcc</samp> as a shared library, these options
  349. force the use of either the shared or static version, respectively.
  350. If no shared version of <samp>libgcc</samp> was built when the compiler was
  351. configured, these options have no effect.
  352. </p>
  353. <p>There are several situations in which an application should use the
  354. shared <samp>libgcc</samp> instead of the static version. The most common
  355. of these is when the application wishes to throw and catch exceptions
  356. across different shared libraries. In that case, each of the libraries
  357. as well as the application itself should use the shared <samp>libgcc</samp>.
  358. </p>
  359. <p>Therefore, the G++ driver automatically adds <samp>-shared-libgcc</samp>
  360. whenever you build a shared library or a main executable, because C++
  361. programs typically use exceptions, so this is the right thing to do.
  362. </p>
  363. <p>If, instead, you use the GCC driver to create shared libraries, you may
  364. find that they are not always linked with the shared <samp>libgcc</samp>.
  365. If GCC finds, at its configuration time, that you have a non-GNU linker
  366. or a GNU linker that does not support option <samp>--eh-frame-hdr</samp>,
  367. it links the shared version of <samp>libgcc</samp> into shared libraries
  368. by default. Otherwise, it takes advantage of the linker and optimizes
  369. away the linking with the shared version of <samp>libgcc</samp>, linking with
  370. the static version of libgcc by default. This allows exceptions to
  371. propagate through such shared libraries, without incurring relocation
  372. costs at library load time.
  373. </p>
  374. <p>However, if a library or main executable is supposed to throw or catch
  375. exceptions, you must link it using the G++ driver, or using the option
  376. <samp>-shared-libgcc</samp>, such that it is linked with the shared
  377. <samp>libgcc</samp>.
  378. </p>
  379. </dd>
  380. <dt><code>-static-libasan</code></dt>
  381. <dd><a name="index-static_002dlibasan"></a>
  382. <p>When the <samp>-fsanitize=address</samp> option is used to link a program,
  383. the GCC driver automatically links against <samp>libasan</samp>. If
  384. <samp>libasan</samp> is available as a shared library, and the <samp>-static</samp>
  385. option is not used, then this links against the shared version of
  386. <samp>libasan</samp>. The <samp>-static-libasan</samp> option directs the GCC
  387. driver to link <samp>libasan</samp> statically, without necessarily linking
  388. other libraries statically.
  389. </p>
  390. </dd>
  391. <dt><code>-static-libtsan</code></dt>
  392. <dd><a name="index-static_002dlibtsan"></a>
  393. <p>When the <samp>-fsanitize=thread</samp> option is used to link a program,
  394. the GCC driver automatically links against <samp>libtsan</samp>. If
  395. <samp>libtsan</samp> is available as a shared library, and the <samp>-static</samp>
  396. option is not used, then this links against the shared version of
  397. <samp>libtsan</samp>. The <samp>-static-libtsan</samp> option directs the GCC
  398. driver to link <samp>libtsan</samp> statically, without necessarily linking
  399. other libraries statically.
  400. </p>
  401. </dd>
  402. <dt><code>-static-liblsan</code></dt>
  403. <dd><a name="index-static_002dliblsan"></a>
  404. <p>When the <samp>-fsanitize=leak</samp> option is used to link a program,
  405. the GCC driver automatically links against <samp>liblsan</samp>. If
  406. <samp>liblsan</samp> is available as a shared library, and the <samp>-static</samp>
  407. option is not used, then this links against the shared version of
  408. <samp>liblsan</samp>. The <samp>-static-liblsan</samp> option directs the GCC
  409. driver to link <samp>liblsan</samp> statically, without necessarily linking
  410. other libraries statically.
  411. </p>
  412. </dd>
  413. <dt><code>-static-libubsan</code></dt>
  414. <dd><a name="index-static_002dlibubsan"></a>
  415. <p>When the <samp>-fsanitize=undefined</samp> option is used to link a program,
  416. the GCC driver automatically links against <samp>libubsan</samp>. If
  417. <samp>libubsan</samp> is available as a shared library, and the <samp>-static</samp>
  418. option is not used, then this links against the shared version of
  419. <samp>libubsan</samp>. The <samp>-static-libubsan</samp> option directs the GCC
  420. driver to link <samp>libubsan</samp> statically, without necessarily linking
  421. other libraries statically.
  422. </p>
  423. </dd>
  424. <dt><code>-static-libstdc++</code></dt>
  425. <dd><a name="index-static_002dlibstdc_002b_002b"></a>
  426. <p>When the <code>g++</code> program is used to link a C++ program, it
  427. normally automatically links against <samp>libstdc++</samp>. If
  428. <samp>libstdc++</samp> is available as a shared library, and the
  429. <samp>-static</samp> option is not used, then this links against the
  430. shared version of <samp>libstdc++</samp>. That is normally fine. However, it
  431. is sometimes useful to freeze the version of <samp>libstdc++</samp> used by
  432. the program without going all the way to a fully static link. The
  433. <samp>-static-libstdc++</samp> option directs the <code>g++</code> driver to
  434. link <samp>libstdc++</samp> statically, without necessarily linking other
  435. libraries statically.
  436. </p>
  437. </dd>
  438. <dt><code>-symbolic</code></dt>
  439. <dd><a name="index-symbolic"></a>
  440. <p>Bind references to global symbols when building a shared object. Warn
  441. about any unresolved references (unless overridden by the link editor
  442. option <samp>-Xlinker -z -Xlinker defs</samp>). Only a few systems support
  443. this option.
  444. </p>
  445. </dd>
  446. <dt><code>-T <var>script</var></code></dt>
  447. <dd><a name="index-T"></a>
  448. <a name="index-linker-script"></a>
  449. <p>Use <var>script</var> as the linker script. This option is supported by most
  450. systems using the GNU linker. On some targets, such as bare-board
  451. targets without an operating system, the <samp>-T</samp> option may be required
  452. when linking to avoid references to undefined symbols.
  453. </p>
  454. </dd>
  455. <dt><code>-Xlinker <var>option</var></code></dt>
  456. <dd><a name="index-Xlinker"></a>
  457. <p>Pass <var>option</var> as an option to the linker. You can use this to
  458. supply system-specific linker options that GCC does not recognize.
  459. </p>
  460. <p>If you want to pass an option that takes a separate argument, you must use
  461. <samp>-Xlinker</samp> twice, once for the option and once for the argument.
  462. For example, to pass <samp>-assert definitions</samp>, you must write
  463. <samp>-Xlinker -assert -Xlinker definitions</samp>. It does not work to write
  464. <samp>-Xlinker &quot;-assert definitions&quot;</samp>, because this passes the entire
  465. string as a single argument, which is not what the linker expects.
  466. </p>
  467. <p>When using the GNU linker, it is usually more convenient to pass
  468. arguments to linker options using the <samp><var>option</var>=<var>value</var></samp>
  469. syntax than as separate arguments. For example, you can specify
  470. <samp>-Xlinker -Map=output.map</samp> rather than
  471. <samp>-Xlinker -Map -Xlinker output.map</samp>. Other linkers may not support
  472. this syntax for command-line options.
  473. </p>
  474. </dd>
  475. <dt><code>-Wl,<var>option</var></code></dt>
  476. <dd><a name="index-Wl"></a>
  477. <p>Pass <var>option</var> as an option to the linker. If <var>option</var> contains
  478. commas, it is split into multiple options at the commas. You can use this
  479. syntax to pass an argument to the option.
  480. For example, <samp>-Wl,-Map,output.map</samp> passes <samp>-Map output.map</samp> to the
  481. linker. When using the GNU linker, you can also get the same effect with
  482. <samp>-Wl,-Map=output.map</samp>.
  483. </p>
  484. </dd>
  485. <dt><code>-u <var>symbol</var></code></dt>
  486. <dd><a name="index-u"></a>
  487. <p>Pretend the symbol <var>symbol</var> is undefined, to force linking of
  488. library modules to define it. You can use <samp>-u</samp> multiple times with
  489. different symbols to force loading of additional library modules.
  490. </p>
  491. </dd>
  492. <dt><code>-z <var>keyword</var></code></dt>
  493. <dd><a name="index-z"></a>
  494. <p><samp>-z</samp> is passed directly on to the linker along with the keyword
  495. <var>keyword</var>. See the section in the documentation of your linker for
  496. permitted values and their meanings.
  497. </p></dd>
  498. </dl>
  499. <div class="footnote">
  500. <hr>
  501. <h4 class="footnotes-heading">Footnotes</h4>
  502. <h3><a name="FOOT1" href="#DOCF1">(1)</a></h3>
  503. <p>On some systems, &lsquo;<samp>gcc -shared</samp>&rsquo;
  504. needs to build supplementary stub code for constructors to work. On
  505. multi-libbed systems, &lsquo;<samp>gcc -shared</samp>&rsquo; must select the correct support
  506. libraries to link against. Failing to supply the correct flags may lead
  507. to subtle defects. Supplying them in cases where they are not necessary
  508. is innocuous.</p>
  509. </div>
  510. <hr>
  511. <div class="header">
  512. <p>
  513. Next: <a href="Directory-Options.html#Directory-Options" accesskey="n" rel="next">Directory Options</a>, Previous: <a href="Assembler-Options.html#Assembler-Options" accesskey="p" rel="prev">Assembler Options</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>
  514. </div>
  515. </body>
  516. </html>