2

Very new to Ada and have started to learn by doing a Hello World tutorial in GNAT GPS. I'm having a hard time figuring out an error when I compile my code. The error looks like a source file dir issue. But I'm highly unfamiliar with the error output in this type of IDE.

Here is the code I'm trying to compile and run (file: main.adb):

with Ada.Text_IO;

procedure Main is

begin
   Ada.text_IO.Put_Line("Hello world!");
   null;
end Main;

Image of code and GPS IDE

Here's the build error I'm receiving:

gprbuild -d -P/Users/myname/Desktop/Test/default.gpr /Users/myname/Desktop/Test/src/main.adb
Compile
   [Ada]          main.adb
Bind
   [gprbind]      main.bexch
   [Ada]          main.ali
Link
   [link]         main.adb
ld: library not found for -lSystem
collect2: error: ld returned 1 exit status
gprbuild: link of main.adb failed
gprbuild: failed command was: /users/myname/opt/gnat/2019/bin/gcc main.o b__main.o -L/Users/myname/Desktop/Test/obj/ -L/Users/myname/Desktop/Test/obj/ -L/users/myname/opt/gnat/2019/lib/gcc/x86_64-apple-darwin17.7.0/8.3.1/adalib/ /users/myname/opt/gnat/2019/lib/gcc/x86_64-apple-darwin17.7.0/8.3.1/adalib/libgnat.a -Wl,-rpath,@executable_path/ -Wl,-rpath,@executable_path/../../..//opt/gnat/2019/lib/gcc/x86_64-apple-darwin17.7.0/8.3.1/adalib -o main
[2019-10-19 11:34:54] process exited with status 4, elapsed time: 01.95s

I'm assuming I installed Ada incorrectly and or GPS. Any suggestions or thoughts? Thank you.

Update/Additional thoughts:

One other thing I'm assuming is that the project is unable to find the Ada source code since the project is saved on the /desktop?

animuson
  • 53,861
  • 28
  • 137
  • 147
  • It appears that GNAT is not correctly installed. There is no reason to assume that the project must be saved to a particular directory. When creating the project using GPS the GPS project will identify all the necessary source file directories. – Jim Rogers Oct 19 '19 at 19:39
  • The problem isn’t with your code being on the desktop or the GNAT installation. That’s a linking error, meaning that the compilation was successful but the linker couldn’t find `libSystem.dylib` (a basic Darwin system library). – Simon Wright Oct 19 '19 at 19:55

1 Answers1

4

I see you’re running on macOS and using GNAT CE 2019. You need to install Xcode (from the app store, under Develop).

I wrote it up here, but to summarise,

  • In future, Apple won’t provide includes in /usr/include but instead in the SDK,
  • clang knows about this but GCC doesn’t,
  • AdaCore’s response has been to generate their compiler with the system root inside the Xcode SDK,
  • the system root affects libraries as well as headers,
  • so no Xcode means no system libraries (in spite of the libraries being in /usr/lib as always!)
Simon Wright
  • 25,108
  • 2
  • 35
  • 62
  • Thank you for the suggestions and feedback Simon. I really appreciate it. I do have Xcode installed and Xcode Tools. Also I removed the /opt directory from my machine and reinstalled the Ada Community Tools. No effect, with same error. I’m currently reimagining my machine to see if that might help with the reinstallation. I just upgraded to macOS Catalina and are thinking that could have messed with it. I’ll keep you updated on what I find out. –  Oct 19 '19 at 23:53
  • The scratch disk I’m running Catalina from was updated High Sierra -> Mojave -> Catalina. I had no problems with a fresh install of GNAT CE 2019 (to `~/opt/GNAT`) with the Mojave Xcode or an update to the Catalina Xcode. Do you actually have `/usr/lib/libSystem*`? (the source code was on the desktop). – Simon Wright Oct 20 '19 at 14:13
  • Do you have Xcode in `/Applications/Xcode.app`, where it ought to be? I moved mine away from there and got exactly the error you did – Simon Wright Oct 21 '19 at 08:10