Jump to page: 1 2 3
Thread overview
Instructions for compilation from multiple source files
Nov 10, 2014
Solomon E
Nov 10, 2014
bearophile
Nov 10, 2014
Suliman
Nov 10, 2014
Solomon E
Nov 10, 2014
Mike Parker
Nov 10, 2014
ketmar
Nov 10, 2014
Solomon E
Nov 10, 2014
Russel Winder
Nov 10, 2014
Solomon E
Nov 10, 2014
ketmar
Nov 10, 2014
Solomon E
Nov 10, 2014
ketmar
Nov 10, 2014
Solomon E
Nov 10, 2014
ketmar
Nov 10, 2014
Solomon E
Nov 10, 2014
ketmar
Nov 10, 2014
Solomon E
Nov 11, 2014
Solomon E
Nov 10, 2014
Russel Winder
Nov 10, 2014
John Colvin
Nov 10, 2014
Solomon E
Nov 10, 2014
ketmar
November 10, 2014
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.

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.

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.

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.

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.
November 10, 2014
Solomon E:

> 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.

It's not in flux.
A simple way to compile more than one file is to put them in the same compilation unit (almost the same if you want to create a lib):

dmd a.d b.d

Otherwise you can also use ddmd and let it find the module dependencies by itself.

Bye,
bearophile
November 10, 2014
> dmd a.d b.d
>
> Otherwise you can also use ddmd and let it find the module dependencies by itself.
>

Am I right understand that if I will put all needed files at src folder and name main file App.d dub will add all needed files to App.d ?
November 10, 2014
On Mon, 10 Nov 2014 12:10:36 +0000
Solomon E via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com>
wrote:

> 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.
you'd better not use command-line toolchain, they all aren't ready. if you can't figure out how to use some compiler of GCC suite, you'd better try some IDEs.


November 10, 2014
On Monday, 10 November 2014 at 12:21:51 UTC, bearophile wrote:

> It's not in flux.
> A simple way to compile more than one file is to put them in the same compilation unit (almost the same if you want to create a lib):
>
> dmd a.d b.d
>
> Otherwise you can also use ddmd and let it find the module dependencies by itself.
>
> Bye,
> bearophile

That's not applicable because I'm not using DMD. Also that
doesn't answer where a .o or .a file comes from, whether there's
any difference between them besides the name, and if so what.
I've compiled a lot of little examples and tests of D from single
source files, but I haven't seen any .o or .a files yet.

I was hoping there were instruction pages or documentation pages
on how to compile D projects that have multiple source files.
November 10, 2014
On Monday, 10 November 2014 at 12:49:46 UTC, ketmar via
Digitalmars-d-learn wrote:

> you'd better not use command-line toolchain, they all aren't ready. if
> you can't figure out how to use some compiler of GCC suite, you'd
> better try some IDEs.

So there's such a lack of documentation on D that I'm *supposed*
to just guess and experiment about what .o and .a files might be,
or hope that an IDE frontend writer guessed right? There's no
specification whatsoever?
November 10, 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@ekiga.net 41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@winder.org.uk London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder


November 10, 2014
On Mon, 2014-11-10 at 13:01 +0000, Solomon E via Digitalmars-d-learn wrote:
> On Monday, 10 November 2014 at 12:49:46 UTC, ketmar via Digitalmars-d-learn wrote:
> 
> > you'd better not use command-line toolchain, they all aren't
> > ready. if
> > you can't figure out how to use some compiler of GCC suite,
> > you'd
> > better try some IDEs.
> 
> So there's such a lack of documentation on D that I'm *supposed* to just guess and experiment about what .o and .a files might be, or hope that an IDE frontend writer guessed right? There's no specification whatsoever?

ketmar was just being a teensy weensy bit over-dramatic.

He was trying to point out that gdc is part of the GCC and so all the GCC documentation is relevant for gdc. D thus gets huge amounts of documentation for gdc for free.

-- 
Russel. ============================================================================= Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder@ekiga.net 41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@winder.org.uk London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder


November 10, 2014
On Monday, 10 November 2014 at 13:11:45 UTC, Russel Winder via
Digitalmars-d-learn wrote:
> ketmar was just being a teensy weensy bit over-dramatic.
>
> He was trying to point out that gdc is part of the GCC and so all the
> GCC documentation is relevant for gdc. D thus gets huge amounts of
> documentation for gdc for free.

The problem that I'm having with this seems to be with GDC, not
the rest of the D community. The following is a quote of the
entire amount of information in the GDC man page on the following
compiler options and file extensions:

SYNOPSIS
        gdc [-c]
            [-g] [-pg] [-Olevel]
            [-Idir...] [-Ldir...]
            [-o outfile] infile...

        For any given input file, the file name suffix determines
what kind of
        compilation is done:

        file.d
            D source files.

        file.di
            D interface files.

        file.o
            Object files to link in.

        file.a
            Library files to link in


So I could *guess* that a dot o file is the equivalent of a .obj
file an Windows, and *guess* that a dot a file is the equivalent
of a .lib file on Windows, then follow some Windows instructions
as on the page
http://wiki.dlang.org/Compiling_and_linking_with_DMD_on_Windows
but I would totally be guessing, and I still wouldn't know where
to get any .a files, but I could *guess* that I would get a .o
file by running the compiler and naming the output a .o file by
using the -o switch. I would be totally guessing, and if I'm
wrong, all my builds would be wrong and incompatible with other
people's build systems.

Again, I was hoping there would be some instruction pages or
documentation pages or specifications on this subject.
November 10, 2014
On 11/10/2014 9:55 PM, Solomon E wrote:
> On Monday, 10 November 2014 at 12:21:51 UTC, bearophile wrote:

>
> That's not applicable because I'm not using DMD. Also that
> doesn't answer where a .o or .a file comes from, whether there's
> any difference between them besides the name, and if so what.
> I've compiled a lot of little examples and tests of D from single
> source files, but I haven't seen any .o or .a files yet.

.o and .a have are not a D-specific thing. They are part of the ecosystem on Posix systems. If you are using C or C++, you would still be dealing with them. You input source files to a compiler, it creates object files (.o) and you feed those to a linker to get an executable binary or an archiver to get a library (.a), which is a collection of object files that can be linked to an executable.

Please do not confuse this with having anything directly to do with D. Most of the D compiler implementations on Linux use the GNU compiler collection (gcc) toolchain to generate binaries, and gcc is a core part of the Linux ecosystem. If you are working on the command line in Linux, it's something you have to get your head around eventually. The same goes for any platform you use.

>
> I was hoping there were instruction pages or documentation pages
> on how to compile D projects that have multiple source files.

Assume a directory structure like so:

-project
--source
----main.d
----foo
------bar.d

cd project/source
gdc main.d foo/bar.d -o myapp

No matter which compiler you are using, you have to pass every source file to it that you want it to compile into the final executable. The only way around this is to use a build tool like dub or rdmd, which will hand everything to the compiler for you.

When using gdc, since it is based on gcc then the output for a binary is always named 'a.out'. The -o option will cause the binary to be named what ever you set it to, in this case 'myapp'.

Notice that the paths are relative to the currently directory. If main.d imports foo.bar, then DMD will know do look for foo/bar.d from the current directory. You can change this up a bit like so:

cd project
gdc -Isource source/main.d source/foo/bar.d -o myapp

Here, the -I option tells dmd to look for imports *in* the source directory. Now, when it fails when main.d imports foo.bar and the compiler fails to find the file foo/bar.d relative the the current directory, it will then look in source/foo/bar.d and find it. That's only for imports though and not for compilation. When using third-party libraries, you will usually need to pass the -I switch.

No matter what compiler you use, you can usually run something like gdc --help to get a list of command line switches and what they do. For dmd, you can just type 'dmd' to print them.

Since you are using gdc, I suggest you google for tutorials on how to the gcc tools, particularly compiling. The process in D is basically the same and the fundamentals of compiling and linking are the same across compilers. I don't use gdc, but I believe it supports most of the standard gcc compiler switches and adds some specific ones for D.

Perhaps a page could be added to the Wiki explaining the basics of compilation with the different compilers, but most of the existing documentation assumes that users will know at least the basics of using a compiler from the command line.

Ali Çehreli has put together a fantastic book [1] that is targeted at beginners. It has a section introducing DMD. That would also be a good place for you to start. If you understand the fundamentals of one compiler, you can pick them all up.

[1] http://ddili.org/ders/d.en/index.html


« First   ‹ Prev
1 2 3