www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Fishy linker behavior

This is certainly an interesting one...  This has been jabbing me in the sides
now for the last couple hours.

I have a simple client program that wants to use Derelict's SDL bindings (check
out www.dsource.org).  I have the Derelict libraries compiled correctly with no
warnings/errors on Linux and stored in the library search path.  Obviously, they
are linked in statically.

-----------------------------
module	udpclient;

import	derelict.sdl.sdl;
import	derelict.sdl.net;

int main(char[][] args) {
// Load SDL's DLLs
DerelictSDL_Load();
DerelictSDLNet_Load();

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

Now, my build line looks like this:

dmd udpclient.d -L-lsqlite3 -L-lderelictSDL -L-lderelictUtil -L-lderelictSDLNet
-L-ldl

However, the linker gives me strange errors when I try to link: (output
summarized)

undefined reference to `_D9invariant12_d_invariantFC6ObjectZv'
undefined reference to `_d_assert'
undefined reference to `_D9invariant12_d_invariantFC6ObjectZv'
undefined reference to `_D9invariant12_d_invariantFC6ObjectZv'

Notice the undefined reference to `_d_assert'.  That's a phobos function!
Obviously the phobos library is linked in, so that doesn't make sense.  The real
kicker is when I make this tiny change to the udpclient.d source:

-----------------------------------
int main(char[][] args) {
// This new dummy assert added...
assert( 1 == 1 );

// Load SDL's DLLs
-----------------------------------

After that, gcc's linker output is reduced to this:

undefined reference to `_D9invariant12_d_invariantFC6ObjectZv'
undefined reference to `_D9invariant12_d_invariantFC6ObjectZv'
undefined reference to `_D9invariant12_d_invariantFC6ObjectZv'

Notice the magical disappearance of undefined reference: `_d_assert' ?  Now, I
add this dummy class definition to my udpclient.d source code:

class DummyClass {
void somefunc()
in {
assert ( 1 == 1 );
}
out {
assert ( 1 > 0 );
}
body {
printf("hi\n");
}
}

All my linker errors disappear and the code correctly compiles!

Fishy things going on here!!  Is this a problem with GCC or DMD?  I'm using
version 0.120 of DMD and GCC 3.3.5.  If any more information is required to
debug this problem, let me know and I'll be glad to assist.

Regards,
James Dunne
Apr 14 2005