Instructions for compilation from multiple source files

Russel Winder via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Nov 10 05:08:14 PST 2014


On Mon, 2014-11-10 at 12:10 +0000, Solomon E via Digitalmars-d-learn
wrote:
> I wanted to know how to compile a D program that has multiple
> source files. I looked under "Modules" in the language reference,
> but there isn't anything there about compilation, or anything
> about where to put the source files, or anything about how the
> compiler finds the files to use.

There are effectively two models of compilation for D codes:

1. Compile each module individually and then link all the object files
together. This is the traditional C, C++, Fortran way of working.

2. Compile all module source files all at once. In this mode you can
either list all the source files or just the main one and see if the
compiler correctly find all the dependencies.

For 1 you generally need a build tool. I will, of course (but this is
left as an exercise for the reader), suggest using SCons and its
magnificent D tool. There is also D support for CMake. I believe Waf has
some D support. For Make and any other out of date system, you are on
your own!

I tend to use SCons for mode 2 as well as I can add extras.

> I'm currently using the GDC compiler, because I don't trust the
> DMD Debian package enough to install it, considering it has
> Google adsense ads in its HTML pages, which is against even
> Google's policy.

If the deb file (or any of the packages) on the D web site have such
things then they are broken, and you are quite right, should be ignored.
I am using Debian Sid and get my packages from D-Apt,
http://d-apt.sourceforge.net/ . This works very well.

> I looked around the D Wiki for instructions on compilation, and
> it doesn't seem that there are any instructions other than for
> DMD on Windows and for compiling a hello world with one source
> file. The GDC site has no instructions or documentation on how to
> do compilation.

GDC is really just GCC in disguise, and rather usefully compiling D
instead of C, C++, Fortran, Ada, Objective-C, etc. So if you have ever
used gcc or g++ commands you more or less already know how to use gdc.

> The GDC man page is the same as the GDC info page. It lists some
> options for the compiler without listing what they do in the case
> of D.
> 
> I'm not getting any .o or .a files out of the compiler, only
> a.out or whatever file name I choose with the -o option.
> 
> I don't want to have to guess how to do it and experiment, as if
> it's all implementation defined and in flux to the degree that
> that's the only way to compile anything.

Actually that is a shame. We should all be prepared to experiment, play
(and have fun). I agree there is less documentation than would be good
around D generally, but it is a FOSS project without a team of paid
staff to work 100% on it. Because volunteers generally prefer to work on
code, the documentation tends to get a little left behind. What is
needed is for some of the companies using D to give back by in some way
funding more work on the documentation.

> If there aren't instructions or documentation on how to compile
> more than one file into a finished D runnable project in a
> correct way that can grow with larger projects, then I'll have to
> take it as implied that D is just not ready or not welcoming and
> I shouldn't use it.

I think that would be a huge over assumption. D has been ready for use
for ages and is in use in many places, just not as many as would be good
for D and for native programming in general.

I hope you stay with D and discover how welcoming the community is.

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20141110/4bde0893/attachment.sig>


More information about the Digitalmars-d-learn mailing list