Thread overview
Modules/Libraries
Jan 03, 2007
Joseph Colton
Jan 03, 2007
Joseph Colton
Jan 03, 2007
Frits van Bommel
January 03, 2007
I would like to create a module for creating ODF documents using D.  I have done this before in Perl and Python, but I was able to easily figure out how to create modules there.

I currently have two files that I am trying to get to interface correctly. Here is the first file called ooolib.d:

module ooolib;
class Calc
{
public:
        this()
        {
        }

        char[] echo(char[] name)
        {
                return name;
        }
}

The second file is called test.d:

import std.stdio;
import ooolib;
void main(char[][] args)
{
    Calc doc = new Calc();
    writefln(doc.echo("Hello World"));
}

For some reason I cannot seem to get them to work together.  I get a lot errors that claim there are undefined references.  I am obviously missing something, does anyone know what I am missing?
January 03, 2007
Joseph Colton wrote:
> I would like to create a module for creating ODF documents using D.  I have
> done this before in Perl and Python, but I was able to easily figure out how
> to create modules there.
> 
> I currently have two files that I am trying to get to interface correctly.
> Here is the first file called ooolib.d:
> 
> module ooolib;
> class Calc
> {
> public:
>         this()
>         {
>         }
> 
>         char[] echo(char[] name)
>         {
>                 return name;
>         }
> }
> 
> The second file is called test.d:
> 
> import std.stdio;
> import ooolib;
> void main(char[][] args)
> {
>     Calc doc = new Calc();
>     writefln(doc.echo("Hello World"));
> }
> 
> For some reason I cannot seem to get them to work together.  I get a lot
> errors that claim there are undefined references.  I am obviously missing
> something, does anyone know what I am missing?

The code itself looks fine.  What's your compile command line?  Are you including both modules in arguments to the compiler?  Something like:
dmd test.d ooolib.d

(Not attacking your intelligence.  Its just a common first mistake.)
There's also the Build utility if you worry about command lines getting long.
http://dsource.org/projects/build

-- Chris Nicholson-Sauls
January 03, 2007
== Quote from Chris Nicholson-Sauls (ibisbasenji@gmail.com)'s article
> Joseph Colton wrote:
> > I would like to create a module for creating ODF documents using D.  I have done this before in Perl and Python, but I was able to easily figure out how to create modules there.
> >
> > I currently have two files that I am trying to get to interface correctly. Here is the first file called ooolib.d:
> >
> > module ooolib;
> > class Calc
> > {
> > public:
> >         this()
> >         {
> >         }
> >
> >         char[] echo(char[] name)
> >         {
> >                 return name;
> >         }
> > }
> >
> > The second file is called test.d:
> >
> > import std.stdio;
> > import ooolib;
> > void main(char[][] args)
> > {
> >     Calc doc = new Calc();
> >     writefln(doc.echo("Hello World"));
> > }
> >
> > For some reason I cannot seem to get them to work together.  I get a lot errors that claim there are undefined references.  I am obviously missing something, does anyone know what I am missing?
> The code itself looks fine.  What's your compile command line?  Are you
including both
> modules in arguments to the compiler?  Something like:
> dmd test.d ooolib.d
> (Not attacking your intelligence.  Its just a common first mistake.)
> There's also the Build utility if you worry about command lines getting long.
> http://dsource.org/projects/build
> -- Chris Nicholson-Sauls

Thank you.  That solved the problem.
January 03, 2007
Chris Nicholson-Sauls wrote:
> The code itself looks fine.  What's your compile command line?  Are you including both modules in arguments to the compiler?  Something like:
> dmd test.d ooolib.d

There's also the alternative option if you want to compile each .d file separately: pass -c to just compile without linking.
Later, pass all the generated .o or .obj files (on Linux and Windows, respectively) to dmd to link them.

But as Chris mentioned build comes highly recommended by many people. Not by me personally though, since I don't have much first-hand experience with it. Code::Blocks[1] is what I use and also works quite well. (don't get rc2, it's ancient)


[1]: to get it, go to http://www.codeblocks.org and get a recent nightly