Trying to use GPS for Ada and keep having problems trying to compile and run the code

209 Views Asked by At

I am currently trying to run a program in GPS and this is my first time trying to use Ada and don't quite understand some things to it. I have some code that was told was supposed to run but can't seem to get it running. When I try to compile it or run the code, I keep getting an error message: "end of file expected. file can only be one compilation unit." I also included a photo to help show the problem. I'd appreciate any tips or hints on how to solve this please!

enter image description here

2

There are 2 best solutions below

2
Niklas Holsti On

From the image, you seem to have a source file that contains both the declaration (or "spec", "specification") of a package named CircularQueue, and the body (the implementation) of that package. For the GNAT compiler and GPS such combined files are not supported. You should put the declaration of the package and the body of the package each into its own source file. In general, for GNAT/GPS each Ada "compilation unit" must be in its own source file. (This is also good for version control and to reduce unnecessary recompilations.)

The package declaration is the first part of your current file, from

generic
   ...
package CircularQueue is

to the first occurrence of

end CircularQueue;

That should be in its own file, which (by GNAT/GPS convention) should be called circularqueue.ads. The final "s" stands for "spec" or "specification".

The body of the package forms the rest of your current file, from

package body CircularQueue is

to the second (and last) occurrence of

end CircularQueue;

The body should be in its own file, which (by GNAT/GPS convention) should be called circularqueue.adb. The final "b" stands for "body".

The first line of your current source file is a so-called "context clause" and says that your code will use the predefined package Ada.Text_IO. Such context clauses should be put at the start of the spec file and/or the body file, depending on which file needs it. In this case, the spec does not refer to Ada.Text_IO, but the body does, so this context clause should be at the start of the body file (circularqueue.adb).

HTH

0
Maxim Reznik On

If you use GNAT Studio the very first time, then I suggest you to spend a few minutes by reading the tutorial.