import syntax

Mike Parker aldacron71 at yahoo.com
Mon Jul 3 23:32:03 PDT 2006


Karl Bochert wrote:
ges?
> 
> I guess the work-around is to use the -I compiler switch which seems like a
> terrible approach to me, moving information that should be in the source to the
> makefile.

It's not a work-around. It's the way the system is intended to work. 
This is more flexible than hard coding relative paths in your code. You 
are telling the compiler to look for a module which resides in a 
'package' on the import path. Don't think of it as a directory tree.

mypackage.mymodule means that 'mymodule' belongs to a package named 
'mypackage'. The fact that the compiler looks for a directory named 
'mypackage' and a file named 'mymodule' are a consequence of the file 
system.

I have three common import locations on my system: the default location 
that DMD defines in sc.ini (it is where phobos resides); a common 
directory where I have all third-party packates that I use 
(C:\dev\D\import is what I've called it); in every project I start I 
keep all of the source in 'src' directory with subdirs matching package 
names. When compiling, I pass -IC:\dev\D\import and -Isrc to the 
compiler (these options are set in a Build response file since I use 
Build and not DMD directly).

I assume you come from a C or C++ background. You're in D land now. 
import statements are not the same as #include directives. Realizing 
that will help you to understand the difference.



More information about the Digitalmars-d-learn mailing list