How to suppress "warning: file name does not match unit name"?

I use gnatmake 13.2.0 on an up-to-date Void Linux machine, and have a shell script to compile and run testt.adb no matter what testt.adb’s outer procedure, function or package is named. So of course I get warnings like the following:

“testt.adb:3:11: warning: file name does not match unit name, should be “hello.adb” [enabled by default]”

Because I’m putting the output of my shell script in my documentation, I’d prefer not to confuse things with this warning. I looked at the output of gnatmake -h and couldn’t find anything that seemed to turn off this particular warning, even in the -gnatwxx section.

Is there a way I can tell gnatmake not to issue this particular warning?

You could begin testt.adb with

pragma Warnings (Off, "file name does not match");
1 Like

Thanks [simonjwright]. Now I have a little bit better idea of what pragmas are.

It being 4am, I figured I wouldn’t get an answer for the next 6 hours, so I fit the shellscript with a grep -v that removed the offending warning. I’m going to go to sleep now, and tomorrow I’ll decide whether to use the pragma or whether to use the shellscript grep -v. Either way, I’ve been wondering what pragmas are, and now have a little better idea, so thanks very much.

I think there’s a pragma for GNAT that allows you to specify a file-name; using that one might override the error.

Another possibility, something like this:

  • A file testt.adb containing:
with Hello; procedure TestT is begin null; end;
  • Then, hello.adb (or whatever name or kind of unit):
procedure Hello is
begin
  null;
end;

Another couple of options:

  1. If using GNAT, you can use pragma Source_File_Name() to specify the actual name of the file - Pragma Source_File_Name (GNAT Reference Manual)

  2. If using GNAT, you can use a GPR file and specify the main there:

project Build is
   for Main use ("proc.adb");  
end Build;

See: 2. GNAT Project Manager — GPR Tools User's Guide 26.0w documentation

3 Likes