You compile Ada code in Windows Command Prompt by calling a compiler driver, usually GNAT, with your source file as the argument: after installing a GNAT toolchain and confirming gcc or gnatmake is on your PATH, run something like gnatmake hello.adb in the folder that holds your source. That single command compiles, binds, and links a typical program, leaving hello.exe beside the source. If Command Prompt instead reports that the command isn't recognized, the toolchain isn't installed or isn't visible on PATH, and that's the problem to fix before anything else.
The rest of this guide covers the full sequence: what to install, how to open a terminal in the right place, the difference between the quick gnatmake route and the explicit compile-bind-link pipeline, how to handle multi-file projects and library units, how to read the errors you'll actually see, and how to verify that what you built is what you meant to build. Commands here are written for Command Prompt specifically; PowerShell users invoke the same executables, though some quoting and path behavior differs.
Prerequisites: What Needs to Be in Place First
You need three things before a compile can succeed: an Ada compiler, a usable command-line environment, and source files with the correct naming conventions.
A GNAT toolchain. The most common free Ada compiler on Windows is GNAT, distributed in several forms. The AdaCore community edition installer bundles GNAT plus the GNAT Programming Studio IDE and is the friendliest starting point. Alternatively, GNAT can be installed through MSYS2 or the Alire package manager, and the GCC toolchains from MinGW-w64 distributions sometimes include a GNAT front end. Any of these provides the same core executables: gcc with Ada support, gnatmake, gnatbind, and gnatlink. The exact version matters less than having a complete, matched set, because mixing a compiler from one install with a binder from another produces confusing failures.
Command Prompt with a working PATH. Installing GNAT does not automatically make it callable from every terminal. The installer typically adds a bin directory to PATH, but if you declined that option or you're using a portable archive, you'll need to add it yourself. The test is simple: open a fresh Command Prompt and run gcc --version. If you see version output, you're set. If you see the Windows message about an unrecognized command, PATH is the issue, and the fix is to add the toolchain's bin folder through the Environment Variables dialog and then open a new terminal, since existing windows don't pick up PATH changes.
Correctly named source files. Ada compilers enforce naming rules that surprise newcomers from C or Python. A file containing the main subprogram Hello must be named hello.adb; a package specification Stack lives in stack.ads and its body in stack.adb. The compiler derives unitcharacter names from filenames, so MyProgram.adb containing procedure Hello will fail with a file-name mismatch. Parent-child units use hyphens in filenames: a child unit Vectors.Operations goes in vectors-operations.ads. Get this wrong and you'll meet a specific error message, covered later.
Opening Command Prompt in the Right Folder
The most common beginner stumble isn't the compiler at all; it's running commands from the wrong directory. Command Prompt starts in your user profile unless you tell it otherwise, and gnatmake hello.adb run from C:\Users\You won't find a file sitting on your Desktop.
The cleanest way to get the working directory right: open File Explorer, navigate into the folder containing your .adb files, click the address bar, type cmd, and press Enter. A Command Prompt opens already pointed at that folder. Confirm with dir and check that your source file appears in the listing; if it doesn't, cd into the correct path or double-check the folder.
A second environmental issue bites people who work across drives. Command Prompt's cd won't change drives on its own, so cd D:\projects\ada from a C: prompt appears to do nothing. Use cd /d D:\projects\ada to change drive and directory together, or type D: first and then cd. This is a Windows shell quirk, not an Ada one, but it derails plenty of first compiles.
Compiling a Single File with gnatmake
For a one-file program, gnatmake is the whole toolchain in one command. Suppose you have hello.adb:
From the folder containing it, run:
You'll see a sequence of lines as gnatmake invokes the compiler, then the binder, then the linker. When it finishes without errors, hello.exe sits in the same folder. Run it with hello (Command Prompt finds executables in the current directory by default; PowerShell requires .\hello).
What actually happened behind that one command is worth knowing, because it explains the next section. gnatmake analyzed the source, discovered it needed the Ada.Text_IO runtime units, compiled them or located prebuilt versions, compiled hello.adb to an object file, ran the binder to produce the initialization and elaboration code that Ada requires, and linked everything into an executable. For small programs this is exactly the right level of automation. For larger ones, you'll want to steer the process.
A few flags earn their keep. -gnatwa turns on most warnings, and warnings in Ada are frequently the early signal of a real bug. -g includes debug information for use with GDB. -O2 enables optimization for release builds. You can stack them: gnatmake -gnatwa -g hello.adb. Note that -gnat flags are compiler switches and -g/-O2 are passed through to the underlying GCC invocation; gnatmake handles that forwarding, which is one reason to use it rather than calling gcc directly for Ada.
The Explicit Pipeline: gcc, gnatbind, gnatlink
Sometimes you want the steps separated: to see exactly which stage failed, to integrate with a build script that compiles many files once and links variants, or to control binding options. The manual pipeline has three stages, and the order is fixed.
Step 1: Compile each source file to an object file.
The -c flag means compile only, no link. This produces hello.o. Repeat for every source file in the partition, or use a wildcard in a batch script. If a file fails to compile, stop here: binding and linking can't succeed with a missing object file.
Step 2: Bind.
The binder reads the .ali file (Ada Library Information) that the compiler wrote alongside the object file. That file records dependencies, elaboration order requirements, and unit interfaces. The binder's output is bhello.adb, an automatically generated Ada source file containing the program's initialization routine, which then must itself be compiled to bhello.o. gnatbind does not compile it for you; that's a separate gcc -c b~hello.adb. This generated-file step is the part of the pipeline people forget, and its absence produces linker errors about a missing main.
Step 3: Link.
gnatlink invokes the linker with the right runtime libraries and startup code, drawing on the same .ali file. The result is hello.exe.
Compare this with gnatmake: the driver runs exactly these steps and manages the generated binder file for you. My recommendation for everyday work is to start with gnatmake and drop to the explicit pipeline only when you have a reason, such as a build system that needs to cache object files or a link step that requires custom flags. Doing the three steps by hand every time is a recipe for forgetting step 2's compilation of the binder output.
Success check for either route: the .exe exists and runs. If hello.exe is present but running it produces no output or an immediate crash, the problem is in the program or its elaboration, not the build commands.
Multi-File Programs and Separate Compilation
Ada's compilation model is unit-based, and it rewards you here. Suppose main.adb withs a package Greeter whose spec is greeter.ads and body is greeter.adb. You don't need to list all three files. From the folder containing them:
gnatmake reads the dependency information in main.ali, sees that Greeter is required, locates greeter.ads and greeter.adb by the naming convention, and compiles them in the correct order. This is the practical payoff of the strict file-naming rules: the toolchain can find units without a project file. Files are recompiled only when their sources or the sources of units they depend on have changed, so repeated builds are fast.
For larger projects, the gnatmake command line grows unwieldy, and that's where GNAT project files (.gpr) come in. A project file describes source directories, object directories, compiler switches, and dependencies in one place. A minimal one looks like this:
With hello.gpr in the current directory, the build becomes:
gprbuild is the modern project-aware builder and is what GNAT's IDE uses underneath. For anything beyond a handful of files, I'd move to a project file early rather than fighting a long command line; it also makes switching between debug and release switch sets a one-line change. gnatmake still respects project files via the -P switch, so gnatmake -P hello.gpr works too, but gprbuild is the better-maintained path.
One subtlety with separate compilation: if you change a package specification, everything that withs it must be recompiled, and gnatmake handles that automatically by consulting the dependency graph. If you ever see stale behavior after an edit, a clean rebuild (delete the object files, or use the project's clean target) resolves it, and its necessity usually points to a build setup that's bypassing the dependency tracking.
Reading the Errors You'll Actually Hit
Ada's compiler diagnostics are unusually precise, which makes them worth learning to read rather than skimming.
"file not found" or "cannot find source file." The named unit doesn't exist under the expected filename in any source directory. Check spelling, check the .ads/.adb extension, and check the parent-child hyphen convention. This is nearly always a naming problem, not a compiler problem.
"file name does not match unit name." You have MyProgram.adb containing procedure Hello. Rename the file to hello.adb.
"missing body for ..." A spec declares a subprogram or the package itself, but no corresponding body exists. Create the .adb, or check that you didn't save the body under the spec's name with the wrong extension.
Syntax errors with a line and column. Ada requires semicolons after declarations and statements, and the compiler points at the exact token where parsing failed. A missing semicolon on the previous line is the usual culprit when the reported position seems fine.
"compilation abandoned" after a long cascade. One early error can trigger many follow-on complaints. Fix the first error reported, recompile, and see how many remain; chasing the tenth message while the first is unfixed wastes time.
Linker errors mentioning main or _gnat symbols. You probably skipped compiling the binder-generated file in a manual pipeline, or you linked with the wrong runtime. Go back to gnatmake or gprbuild and let the driver handle it, then investigate only if the driver also fails.
A practical habit: add -gnatwa to catch warnings, and treat the first error message as the only one worth reading until it's resolved.
Verifying the Build and Running the Program
Verification has three tiers, and it's worth doing all three the first time you set up a toolchain.
First, confirm the artifact exists: dir hello.exe should list the file with a recent timestamp. An executable from yesterday means the build silently didn't run in the folder you think it did.
Second, run it: type hello and check the output. If Windows Defender or SmartScreen blocks a freshly built unsigned executable, that's a security prompt, not a compiler failure; the file was built correctly.
Third, confirm you built the sources you think you built. If the program's output doesn't reflect a recent edit, you're likely running an old executable from a different directory, or the build failed and you ran the previous binary. gnatmake prints "compilation abandoned" on failure but still leaves any prior .exe in place, and running the stale binary is one of the more confusing experiences in this workflow. Deleting the executable before a build, or watching for the absence of error lines, prevents it.
For programs with command-line arguments, pass them after the executable name exactly as in any Windows program: hello arg1 arg2. Ada's Ada.Command_Line package reads them; Command Prompt's quoting rules apply to arguments containing spaces.
When to Stop and Change Approach
Some failures are worth a bounded number of fix attempts before changing tools rather than continuing to poke at the command line. If gcc --version works but gnatmake reports missing runtime libraries, the toolchain install is inconsistent, and reinstalling a matched GNAT distribution is faster than hunting individual library paths. If PATH changes don't take effect in a new terminal, check whether a system-level PATH entry is being overridden by a user-level one, or whether a shell profile script is resetting it. If a project builds with gnatmake on the command line but fails under the IDE, the two are using different project files or switch sets; compare them rather than debugging the compiler.
The stop condition to respect: if you find yourself editing environment variables at the system level, mixing binaries from two different toolchain installs to make a link succeed, or fighting errors that reference runtime internals you don't recognize, step back and do a clean single-toolchain install. Ada's build model is strict precisely so that these situations have clear causes, but untangling a corrupted environment costs more time than a reinstall. Beyond that, ordinary compile errors are yours to fix in the source; nothing in this workflow requires professional intervention.
Frequently Asked Questions
Can I compile Ada with plain gcc hello.adb and skip gnatmake? You can start the process, but a bare gcc hello.adb attempts to compile and link in one step, and Ada linking requires the binder-generated initialization code. For trivial programs the GCC Ada driver sometimes produces a working executable by invoking the binder implicitly, but it doesn't reliably track dependencies across units. Use gnatmake or gprbuild for anything with more than one file.
Why does my program print nothing or crash immediately without a compile error? A successful build guarantees the code compiled, bound, and linked; it doesn't guarantee the elaboration or logic is right. Check that your main procedure actually calls the subprograms you expect, and add a Put_Line early in the main procedure to confirm it's reached. Exceptions raised during elaboration terminate the program before begin runs, and the runtime prints a message naming the exception, which is worth reading rather than dismissing.
Does this work the same in PowerShell? The compiler commands are identical, but two things change: you must prefix a local executable with .\ to run it (.\hello), and some path quoting differs. Environment variable changes still require a fresh terminal. If you're scripting builds, Command Prompt batch files and PowerShell scripts differ enough that it's worth picking one and sticking with it.
What if my source files are in a folder with spaces in the path? Quote paths containing spaces: gnatmake "C:\My Projects\hello.adb" or cd /d "C:\My Projects". Unquoted paths with spaces get split into separate arguments, producing file-not-found errors that look like naming problems but aren't.