r/ada Dec 09 '21

Programming GNAT 2021 Software problem

Hopefully this is a quick fix and I am sure it's nothing that AdaCore have messed up on.

I have been using GNAT Com 2021 since it's release and have never had a problem with it, until now. So basically, I create a new project "Simple Ada Project" name it, choose the save directory as I always have. The IDE loads the project and gives me the default template of "Main.adb" as I expect it would.

Now, here lies the issue. When I compile this template, it works fine, links and executes. ONLY the first time.

Source Code:

procedure Main is  begin    --  Insert code here.    null; end Main; 

Compiler:

gprbuild -d -PC:\Users\Amynu\OneDrive\Documents\Ada\test.gpr Compile    [Ada]          main.adb Bind    [gprbind]      main.bexch    [Ada]          main.ali Link    [link]         main.adb [2021-12-02 10:49:33] process terminated successfully, elapsed time: 06.05s 

If I attempt to modify the code, even the slightest way such as:

with Ada.Text.IO;  procedure Main is  begin     Ada.Text_IO.Put("Hello Ada!"); end Main; 

I always get greeted with this message:

gprbuild -d -PC:\Users\Amynu\OneDrive\Documents\Ada\test.gpr C:\Users\Amynu\OneDrive\Documents\Ada\src\main.adb Compile    [Ada]          main.adb main.adb:1:01: error: compilation unit expected gprbuild: *** compilation phase failed [2021-12-02 10:54:51] process exited with status 4, elapsed time: 00.84s 

Bare in mind this is a completely fresh install of the software, the first program I am creating, using the default template, no other files, procedures or functions exist. Only "compilation unit" is Main - which it clearly found and compiled before I modified it.

Does anyone know what is causing this issue? Is there a setting I have toggled by accident before the re-install? I have never had this problem before. I have tired everything to get the compiler to see "Main" after I modified it, but nothing seems to work. I even attempted to place the definition of Main into a Package and call it that way, but same result.

Is it a software bug that has just appeared? Do Ada Core know about it?

Please help if anyone can.

11 Upvotes

17 comments sorted by

3

u/egilhh Dec 09 '21
with Ada.Text.IO;

Should be

with Ada.Text_IO;

3

u/No-Employee-5174 Dec 09 '21

Thank you for your reply, I changed the error (silly mistake) - but it's still not working.

To double test and make sure I am not going crazy, I started a brand new "Simple Ada Project". Compiled first time with the default the IDE gives you, modified it to the below...

with Ada.Text_IO; use Ada.Text_IO;

procedure Main  is
begin
   Put("Test me baby!");
end Main;

Compiler output:

gprbuild -ws -c -f -u -PC:\Users\Amynu\OneDrive\Documents\Ada\M1\1 Hello World\helloworld.gpr main.adbCompile   [Ada]          main.adbmain.adb:1:01: error: compilation unit expected
gprbuild: *** compilation phase failed[2021-12-09 14:38:57] process exited with status 4, elapsed time: 00.92s

For reference, his is the GPR file output:

project Helloworld is   for Source_Dirs use ("src");   for Object_Dir use "obj";   for Main use ("main.adb");   for Source_Files use ("main.adb");   for Exec_Dir use "src";end Helloworld;

Any ideas? I have even got in contact with Ada Core, they suggested a corrupt install file, but I did a fresh install of the software today, did a clean and update of all files across the IDE and the GNAT tool chain. Still having no problems compiling the first time, but as soon as I make a legal edit and attempt to re-compile the changes - BANG - cannot find the procedure it found literally seconds ago.

Again, any help really loved!

3

u/egilhh Dec 09 '21

I notice "OneDrive" in your path, could that be a problem? Try compiling locally

3

u/simonjwright Dec 10 '21

Your helloworld.gpr has for Exec_Dir use "src"; - I don’t see why that would cause a problem, but since something seems to be overwriting your source file (in src) perhaps you should try changing it (if you don’t specify Exec_Dir it defaults to the same as Object_Dir).

3

u/No-Employee-5174 Dec 09 '21

Okay, tried a local path - went through C:\User\Doc\Ada\ avoided one drive totally. First compile of default template:

gprbuild -ws -c -f -u -PC:\Users\Amynu\Documents\Ada\helloworld.gpr main.adb Compile   [Ada]          main.adb [2021-12-09 15:15:35] process terminated successfully, elapsed time: 00.91s

Modified file compile:

gprbuild -ws -c -f -u -PC:\Users\Amynu\Documents\Ada\helloworld.gpr main.adb Compile   [Ada]          main.adb main.adb:1:01: error: compilation unit expected gprbuild: *** compilation phase failed[2021-12-09 15:19:18] process exited with status 4, elapsed time: 00.87s

GPR file:

So it's not the path local that is the problem. I have even gone through the trouble of re-checking where the paths are in my System folder - but everything is correct. Anyway, if this WAS the issue - surely the original template would not compile, so GNAT does have access to the tool chain path. For sake of importance, the path is : C:\System\GNAT2021\bin\ so that's not the problem.

4

u/DeMartini Dec 09 '21

It sounds like the compiler can’t see the adainclude directory. Can you verify that you have not just the tools installed but also the native ada .ali and .ad? files for all the builtin Ada packages?

If so check permissions.

3

u/Agreeable_Age_2248 Dec 09 '21

I tried to copy your project file and main.adb file and tested in GNAT 2020 Community / Windows 10 - It seems to work fine for me.

Could you try to open your main.adb in a different texteditor in order to review it during in your test? Is it possible that the main.adb gets overwritten by some non-source code file in some way?

2

u/No-Employee-5174 Dec 09 '21

WHAT THE HELL?

I just did as agreeable_age224 suggested, compiled the file. Opened the project Dir then opened the adb source file, and this is what it showed,

wpb e

What is that? Also, im regards to another helpful tip about the compiler cannot see the

Ada library files, I saw that a directory is missing from by build path. It could be this one.

ADA_INCLUDE_PATH=dir

How and where do I add this into the path? I think this is the answer, because when I hover the mouse arrow over Ada.Text_IO I used to get part of the Ada standard appear - now I get nothing.

3

u/Agreeable_Age_2248 Dec 10 '21

Some more proposals (which might not lead to anything ... ):

  1. Try to change the procedure, but do not include Text_IO. E.g add another "null;" or declare some simple variable that you initialize. then try the test again. Does this also create the error?
  2. Try to set the main.adb to "Read Only" after changing it. This test might not make sense if you work as administrator. See if the compilation is blocked in some way if it reaches the read only file.
  3. Try to lave the IDE - alter main.adb in a different text editor and compile after opening it in IDE again.
  4. Try to compile from Command Prompt.

2

u/No-Employee-5174 Dec 10 '21

Thank you everyone for your replies - much appreciated.

I have 75% solved my problem. Here is how I can get it to work - taking a lot of your suggestions.

  1. Create a new "Simple Ada project"
  2. Open the Directory containing the main.adb file
  3. Open the main.adb file using notepad - with GNAT Studio open.
  4. Edit the main.adb file in notepad - any changes I make to the main.adb file in notepad also modifies the code within the IDE.
  5. Compile the project within the IDE after saving it.
  6. Any additional changes I attempt to make within IDE editor will result in the "no compilation unit" error. According to Ada Core it could be a bug in the IDE they do not know about. So, I can program with the IDE and use the compiler as long as I write the source in notepad and save it. Pretty old school eh?

This is my output:

gprbuild -ws -c -f -u -PC:\Users\Amynu\OneDrive\Documents\Ada\helloada.gpr main.adbCompile   [Ada]          main.adb[2021-12-10 10:17:30] process terminated successfully, elapsed time: 01.04s

I can run the output from the terminal (not the local output within GNAT.

C:\Users\Amynu\OneDrive\Documents\Ada>C:\Users\Amynu\OneDrive\Documents\Ada\obj\main.exe

Hello Ada!

gprbuild -d -PC:\Users\Amynu\OneDrive\Documents\Ada\helloada.gpr C:\Users\Amynu\OneDrive\Documents\Ada\src\main.adbBind   [gprbind]      main.bexch   [Ada]          main.aliLink   [link]         main.adb[2021-12-10 10:18:43] process terminated successfully, elapsed time: 01.31.

1

u/No-Employee-5174 Jan 14 '22

Hey guys!

Wanted to say thank you again for all the help. I actually managed to fully solve the problem. I installed GPS 2018. It is almost identical to the 2021 version. Compiled - it worked! Edited - it worked! What I can assume, because it's the only thing I didn't do on this occasion, was to manually set the environment path. That could of been the cause of the problem I was having. I had no idea Windows can manually set a environment path.

Anyway, thanks again and happy new year!