[Bug 202] Undefined reference to libcurl functions with small program (not explicitly using network).

via D.gnu d.gnu at puremagic.com
Tue Feb 16 02:24:15 PST 2016


http://bugzilla.gdcproject.org/show_bug.cgi?id=202

Johannes Pfau <johannespfau at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |johannespfau at gmail.com

--- Comment #10 from Johannes Pfau <johannespfau at gmail.com> ---
I think I've found the problem:

fail.d
------------------------------------------
int main()
{
  import std.stdio;
  import std.conv;

  stdin.byLine();
  char[] s;

  to!int(s);
  parse!int(s);


  return 0;
}
------------------------------------------

ok.d
------------------------------------------
int main()
{
  import std.stdio;
  import std.conv;

  stdin.byLine();
  char[] s;

  parse!int(s);
  to!int(s);


  return 0;
}
------------------------------------------

gdc fail.d // linker error
gdc ok.d  // works

gdc fail.d -c -o fail.o
gdc fail.o // linker error
gdc ok.d -c -o ok.o
gdc ok.o // works

nm fail.o > fail.sym
nm ok.o > ok.sym

diff -u fail.sym ok.sym
-                 U _D3std5array15__T8popFrontTaZ8popFrontFNaNbNiNeKAaZv
+0000000000000000 W _D3std5array15__T8popFrontTaZ8popFrontFNaNbNiNeKAaZv


nm /usr/lib64/libgphobos2.a > sym.txt
_D3std5array15__T8popFrontTaZ8popFrontFNaNbNiNeKAaZv is in curl.o



So what happens is this: In some cases template instances are not emitted as
weak symbols, probably as the compiler correctly infers these templates are
already instantiated in some of the imported modules. The symbol is actually
defined in the curl.o object file though, so it will be linked into the
executable.
I'm not sure whether this actually is a DMD template bug where the compiler
should emit the template (as there is no
_D3std5array15__T8popFrontTaZ8popFrontFNaNbNiNeKAaZv in any other module). OTOH
maybe _D3std5array15__T8popFrontTaZ8popFrontFNaNbNiNeKAaZv should be emitted in
other modules as well (this should be a very common function), but packaging
into a static library merged the weak symbols and unfortunately chose the one
from curl.o?


As a workaround, -femit-templates should work.

-- 
You are receiving this mail because:
You are watching all bug changes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/d.gnu/attachments/20160216/a039eb05/attachment.html>


More information about the D.gnu mailing list