Handling Files with Multiple Units

The basic compilation model of GNAT requires that a file submitted to the compiler have only one unit and there be a strict correspondence between the file name and the unit name.

If you want to keep your files with multiple units, perhaps to maintain compatibility with some other Ada compilation system, you can use gnatname to generate or update your project files. Generated or modified project files can be processed by GNAT.

See Handling Arbitrary File Naming Conventions with gnatname for more details on how to use gnatname.

Alternatively, if you want to permanently restructure a set of ‘foreign’ files so that they match the GNAT rules, and do the remaining development using the GNAT structure, you can simply use gnatchop once, generate the new set of files and work with them from that point on.

Note that if your file containing multiple units starts with a byte order mark (BOM) specifying UTF-8 encoding, then the files generated by gnatchop will each start with a copy of this BOM, meaning that they can be compiled automatically in UTF-8 mode without needing to specify an explicit encoding.