Hi everyone.

I'm new to D, coming from a Java/Python background. I've been reading the excellent "The D Programming Language" book, and want to now start playing around with D.

I'm having an issue with importing. When I have the following file:

file ~/src/sample.d: =====================

import std.stdio;

class A{
        int a = 1;
}

class B{
        A a;
        int b = 2;
        this(A a){
                this.a = a;
        }
}

void main(){
        auto a = new A;
        auto b = new B(a);
        writeln(b.b);
        writeln(b.a.a);
}

...and then at the terminal window:

me@ubuntu:~/src$ rdmd sample.d
1
2

However, if I create a second file to import A from like so:

file ~/src/sample.d: =====================

import std.stdio;
import sample_a;


class B{
        A a;
        int b = 2;
        this(A a){
                this.a = a;
        }
}

void main(){
        auto a = new A;
        auto b = new B(a);
        writeln(b.b);
        writeln(b.a.a);
}

file ~/src/sample_a.d: =====================
class A{
        int a = 1;
}

...and at the terminal:
me@ubuntu:~/src$ rdmd sample.d
/tmp/.rdmd-1000/rdmd-sample.d-94E53075E2E84D963426A11F2B81FDED/objs/sample.o: In function `_Dmain': sample.d:(.text._Dmain+0xa): undefined reference to `_D8sample_a1A7__ClassZ'
collect2: error: ld returned 1 exit status
--- errorlevel 1

I feel like I'm missing something fundamental (and I'm guessing it's because I don't have any experience in "compiled" languages. Can anyone help? It sucks to have everything in one file! :)

Ubuntu 12.10 64bit with the latest D packages (downloaded a few days ago).

I get the same problems in Win7.

Kind regards,
Korey

Reply via email to