comp.lang.ada
 help / color / mirror / Atom feed
From: Ludovic Brenta <ludovic@ludovic-brenta.org>
Subject: Re: Newbie question: How to use gnat make
Date: Sat, 19 Sep 2009 08:20:29 -0700 (PDT)
Date: 2009-09-19T08:20:29-07:00	[thread overview]
Message-ID: <ff86d299-9020-4a1b-915b-45def584d566@h30g2000vbr.googlegroups.com> (raw)
In-Reply-To: b1f1461a-4899-437e-a20b-0a9dbf583c0d@n2g2000vba.googlegroups.com

Markus Bühren wrote on comp.lang.ada:
> I am new to Ada, learning with the book "Programming in Ada 2005" from
> John Barnes. I want to build a program using the GNAT GPL compiler on
> the command line. If my program resides in a single file I just call
>
> gnat make myfun.adb,
>
> but how do I call the compiler if I want to use ("with") packages
> defined in another file? I know the include, compile and link
> procedure from C programs, is it similar in Ada? What about the file
> extensions .ada/.adb/.ads?

*.ads: Ada Specification
*.adb: Ada Body

Each file contains exactly one compilation unit (i.e. a package, a
function, or a procedure; possibly generic).  For child units, name
the file after the fully-qualified name of the unit with a dash as the
separator, e.g.

package Foo.Bar is...      -> foo-bar.ads
package body Foo.Bar is... -> foo-bar.adb

You cannot place multiple compilation units in the same file.

If you follow this convention, then gnatmake does everything else for
you because contrary to C, Ada has built-in support for multiple
compilation.  You do not need any Makefiles or explicit calls to the
linker.  In the simple case where all your source files are in the
same directory, "gnat make myfun" will recompile all units that are
out of date, then bind them, then link them together without your
intervention. The only compilation unit that you name on the command
line is the main procedure; gnat finds all other files by following
the "with" clauses in the main procedure.

In the more complex case where you spread your source files in
multiple directories, you can either use command-line options (i.e.
gnat make -Idir) or project files to tell gnat make where your sources
are.  GNAT project files also allow you to use a non-default naming
convention for your source files but this is only recommended when
migrating from another compiler.  See the GNAT User's Guide for
details on both methods.

HTH and welcome to Ada!

--
Ludovic Brenta.



  reply	other threads:[~2009-09-19 15:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-19 14:05 Newbie question: How to use gnat make Markus
2009-09-19 15:20 ` Ludovic Brenta [this message]
2009-09-19 15:54 ` John B. Matthews
2009-09-20  9:34   ` Markus
2009-09-20 18:17 ` Stephen Leake
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox