Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

"Hello world" won't link on OS X

Moderators: kris

Posted: 09/20/07 23:47:49

I installed Tango using DSSS on my OS X box. The install went cleanly, but I can't compile a simple "hello world" app:

import tango.io.Stdout;
void main() {
        Stdout.formatln("Hello world");
}

Here's what I get:

$ gdmd -version=Posix test.d
/usr/bin/ld: Undefined symbols:
__D5tango2io5Print12__T5PrintTaZ5Print8formatlnMFAaYC5tango2io5Print12__T5PrintTaZ5Print
__D5tango2io6Stdout12__ModuleInfoZ
__D5tango2io6Stdout6StdoutC5tango2io5Print12__T5PrintTaZ5Print
collect2: ld returned 1 exit status

When I look at /usr/lib/libgphobos.a with nm, there are lots and lots of Tango symbols, but not those. Any ideas? Maybe DSSS isn't the right way to build Tango on OS X after all.

Author Message

Posted: 09/21/07 02:36:18

When Tango is built with DSSS, you need to use DSSS (or any other build tool capable of pragma(link)) to link against it. You want

dsss build test.d

Posted: 09/21/07 05:31:50

That seems counterintuitive to me. Why should the build tool I happened to use to compile a library have anything whatsoever to do with the build tool I use to compile a program that uses the library? Isn't a ".a" file just a ".a" file, regardless of what ran the "gdc" commands initially?

Is this considered a bug or a feature? Not being able to compile a quick one-off program by running gdc is a usability problem, IMO. In the past I've frequently done "cat > foo.c; gcc foo.c; ./a.out" sequences to perform little tasks. Are quick one-offs like that just not the norm in Tango-based D development? (I say "Tango-based" because "gdc foo.d; ./a.out" works fine with Phobos, and has been quite handy as I've worked on coming up to speed in D.)

If this is all documented somewhere and I should have just RTFMed first, please accept my apologies for the noise and point me to the relevant text...

Posted: 09/21/07 06:33:23

Tango is just another library, so this is not Tango specific

Posted: 09/21/07 09:10:09

DSSS is a very handy tool, and I think having to use it when compiling your programs is ok, if you already used it to install your library. DSSS really comes to it's own when using it to install/build your whole D environment though.

If you don't use DSSS, but still want all of Tango in a library, run

lib/build-tango.sh mac

and you should have a libgtango of some sort. This needs to be linked on your commandline. libgphobos should be linked automatically. If this also seems unintuitive to you, then it is because there are "historical" reasons for the situation being so. There will most likely be a change in the next couple of Tango releases though, as it should become possible to control what is linked in automatically more properly. GDC don't support the same features as DMD on this yet though.

Posted: 09/21/07 15:44:31 -- Modified: 09/21/07 16:11:26 by
koreth

Building with the script would be perfectly fine. I even tried it initially, but it doesn't work in the current release. (See the "module Exception issue on OS-X" thread.) I built with DSSS because that was supposedly the way to get a working Tango on the Mac.

I'm still puzzled, though, why it should matter. Can someone explain to me, if only just to satisfy my curiosity, what happens differently when I build with DSSS vs. with the script? I've never run across that kind of dependency in any other language -- if I build a .jar file with Ant, say, I can reference that file just fine when I run javac by hand. If the code is missing from the .a file and I get these errors when I compile by hand, where does it come from when DSSS does my build? Is DSSS maintaining its own private stash of bits and pieces of libraries that it doesn't want to include in the archive files? If so, how does it determine what to hide and what not to?

I'm sure there's a perfectly good explanation. As before, if this is documented somewhere, a URL or other pointer would be great. Thanks!

Posted: 09/21/07 15:52:52

Aha, I found the missing pieces. They are split up across a bunch of different .a files. If I run

gdc --version=Posix test.d -lSDG-tango-core -lSDG-tango-io -lSDG-tango-text -lSDG-tango-sys -lSDG-tango-stdc

it links and works. The "SDG-" was what was throwing me off; I had taken a quick peek in my lib directory and not seen any "libtango*" there.

Posted: 09/21/07 18:39:05

You have found parts of what DSSS do, but not necessarily why. DSSS assumes that there is a standard way to name libraries of D code (currently only DSSS conform to this ;), and can use this to analyze the source files and find and link in the correct library files if they are already installed by DSSS. If you look closer, you will see that the different lib file names correspond to certain packages in the Tango hierarchy.