You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GNAT GPS中无法编译运行简单Ada应用求助

解决GNAT GPS编译Hello World时的ld: library not found for -lSystem错误

Hey there! Let's break down what's going on here and fix that linker error you're hitting. First, let's recap your setup details:

你的代码(main.adb)

with Ada.Text_IO;
procedure Main is
begin
Ada.text_IO.Put_Line("Hello world!");
null;
end Main;

收到的构建错误

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

问题原因&解决步骤

First off, your source file being on the desktop isn't the issue—this error happens at the linking stage, not when compiling your Ada code. It's a common compatibility problem between older GNAT versions (like 2019) and newer macOS releases, where the linker can't locate the system library paths properly.

Here's how to fix it step by step:

  1. Make sure Xcode Command Line Tools are installed
    The libSystem.dylib file is part of Apple's developer tools. Open Terminal and run this command to install (or confirm it's already set up):

    xcode-select --install
    

    Follow the on-screen prompts to complete the installation if needed.

  2. Specify the system SDK path for gprbuild
    Older GNAT versions need explicit directions to find the macOS system libraries. You can set this up in GNAT GPS:

    • Open your project in GPS
    • Navigate to Project > Project Properties > Build > Switches > Ada
    • Add this line to the linker flags field:
      -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib
      
      (Note: If you're on a newer macOS version, the SDK path might have a version number like MacOSX13.sdk—check what's in that directory first to use the correct path.)

    You can also test this directly in Terminal to rule out GPS configuration issues:

    gnatmake main.adb -largs -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib
    
  3. Upgrade to a newer GNAT version (highly recommended)
    GNAT 2019 is quite outdated and doesn't play well with modern macOS releases (like Ventura, Sonoma, etc.). The latest GNAT Community versions have built-in fixes for these system compatibility issues. Grab the latest macOS release from AdaCore's official resources.

  4. Verify your GNAT installation
    After making changes, try compiling your Hello World again in GPS. If it still fails, run gnat --version in Terminal to confirm your GNAT installation is properly configured and added to your system PATH.

内容的提问来源于stack exchange,提问作者user12243624

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:16:36