aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Turney <jon.turney@dronecode.org.uk>2017-03-06 17:45:40 +0000
committerJon Turney <jon.turney@dronecode.org.uk>2017-12-08 12:09:18 +0000
commitc6f14b3c81f5a40317452625ef8d56c2612fe776 (patch)
tree350b9e28c1ec8cd292790f620778b099746a5e67
parent2ce4e1e5ad5b694a729e5df13cccaaf514abad45 (diff)
cygwin: Improve discussion of linker library ordering in faq-programming
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
-rw-r--r--winsup/doc/faq-programming.xml37
1 files changed, 36 insertions, 1 deletions
diff --git a/winsup/doc/faq-programming.xml b/winsup/doc/faq-programming.xml
index c0ddd7902..65bfed97e 100644
--- a/winsup/doc/faq-programming.xml
+++ b/winsup/doc/faq-programming.xml
@@ -876,10 +876,45 @@ example, single-stepping from these signals may not work as expected.
<para>A common error is to put the library on the command line before
the thing that needs things from it.
</para>
+
<para>This is wrong <literal>gcc -lstdc++ hello.cc</literal>.
This is right <literal>gcc hello.cc -lstdc++</literal>.
</para>
-</answer></qandaentry>
+
+<para>
+ The first command above (usually) works on Linux, because:
+ <itemizedlist mark="bullet">
+ <listitem>A DT_NEEDED tag for libstdc++ is added when the library name is seen.</listitem>
+ <listitem>The executable has unresolved symbols, which can be found in libstdc++.</listitem>
+ <listitem>When executed, the ELF loader resolves those symbols.</listitem>
+ </itemizedlist>
+</para>
+
+<para>
+ Note that this won't work if the linker flags <literal>--as-needed</literal>
+ or <literal>--no-undefined</literal> are used, or if the library being linked
+ with is a static library.
+</para>
+
+<para>
+ PE/COFF executables work very differently, and the dynamic library which
+ provides a symbol must be fully resolved <emphasis>at link time</emphasis>
+ (so the library which provides a symbol must follow a reference to it).
+</para>
+
+<para>
+ See point 3 in <xref linkend="faq.programming.unix-gui"></xref> for more
+ discussion of how this affects plugins.
+</para>
+
+<para>
+ This also has consequences for how weak symbols are resolved. See <ulink
+ url="https://cygwin.com/ml/cygwin/2010-04/msg00281.html"></ulink> for more
+ discussion of that.
+</para>
+
+</answer>
+</qandaentry>
<qandaentry id="faq.programming.stat64">
<question><para>Why do I get an error using <literal>struct stat64</literal>?</para></question>