12

I installed dmd (2.0 ?) using the windows installer and am trying to compile the following program:

module tcpechoserver;

import std.stdio;

const int MAXPENDING = 5;

int main(char[][] argv)
{
    if(argv.length != 2){
        writef("Usage: %s <port>", argv[0]);
    }

    return 0;
}   

But I get the following compiler error:

Error: module stdio cannot read file 'std\stdio.d'

Are there some paths I have to specify in order to get the standard library to work?

Igor Kustov
  • 3,228
  • 2
  • 34
  • 31
lowerkey
  • 8,105
  • 17
  • 68
  • 102
  • Please post the output of compiling with `dmd -v`. – Bernard Aug 29 '10 at 03:30
  • C:\hope\D>dmd tcpechoserver.d -v parse tcpechoserver importall tcpechoserver import object (C:\D\bin\..\import\object.di) import std.stdio (std\stdio.d) tcpechoserver.d(3): Error: module stdio cannot read file 'std\stdio.d' – lowerkey Aug 29 '10 at 05:27

2 Answers2

8

When you get errors like that, it means that DMD cannot find the import file. If you import foo.bar.xyz, then it expects it to find a xyz.d in some directory foo\bar\.

It searches for this directory in all its standard import paths, as well as the current directory (for example, if you added a directory std next to your tcpechoserver.d with a stdio.d in it, then it would use that). Of course, you don't want that -- you want the standard stdio.d.

You can find what directories it looks it by opening the file

C:\D\dmd2\windows\bin\sc.ini (assuming you installed to the default directory).

Inside that, it should contain the line:

DFLAGS="-I%@P%\..\..\src\phobos" "-I%@P%\..\..\src\druntime\import"

which is telling the compiler to search those paths when looking for import directories. If you don't have that line for whatever reason (or if the line is different) then try adding this line into sc.ini (anywhere under the [Environment] header should do.

Also ensure that the dmd2 directory contains a \src\phobos\std\stdio.d file.

If both these don't work, then I'd recommend reinstalling from scratch.

Peter Alexander
  • 53,344
  • 14
  • 119
  • 168
5

Look at the ~\windows\bin\sc.ini file in your dmd installation directory. It contains implicit command line arguments for dmd, which should look as this for dmd 2.048:

LIB="%@P%\..\lib";\dm\lib

and

DFLAGS="-I%@P%\..\..\src\phobos" "-I%@P%\..\..\src\druntime\import"

If they are ok, and it doesn't works, your installation is probably broken. I recommend you to simply download zipped version of compiler and unpack it over your installation.

Igor Kustov
  • 3,228
  • 2
  • 34
  • 31
Michal Minich
  • 2,387
  • 1
  • 22
  • 30