使用运行时库(MacOS)时缺少 libgnat-2020.dylib

问题描述 投票:0回答:1

我试图弄清楚如何使用 Ada 构建和链接动态库,但我遇到了一个我似乎无法弄清楚的问题。可能只是 MacOS 上的一个错误。

这是我的设置:我创建了一个名为

FCS Middleware
的动态库,我想在我的主项目中使用
Flight Control Software
。库和带有库的主项目都包含编译正常(稍后将详细介绍我的设置)。我什至可以在目标文件夹中执行主项目。

问题是当我将目标文件夹(包含可执行文件和动态库,见下文)移动到另一个文件夹时。在这种情况下,我的主程序不再工作,并且我收到此错误消息:

dyld[15596]: Library not loaded: @rpath/libgnat-2020.dylib
  Referenced from: <9DD7BB9F-4BC0-3F80-9642-36D5228B5867> /Users/robert/Downloads/dist/fcs_software
  Reason: tried: '/Users/robert/Downloads/dist//lib/libgnat-2020.dylib' (no such file), '/Users/robert/Downloads//.obj/libgnat-2020.dylib' (no such file), '/Users/../../..//opt/gnat/2020/lib/gcc/x86_64-apple-darwin17.7.0/8.4.1/adalib/libgnat-2020.dylib' (no such file), '/Users/../../..//opt/gnat/2020/lib/libgnat-2020.dylib' (no such file), '/Users/robert/Downloads/dist//lib/libgnat-2020.dylib' (no such file), '/Users/robert/Downloads//.obj/libgnat-2020.dylib' (no such file), '/Users/../../..//opt/gnat/2020/lib/gcc/x86_64-apple-darwin17.7.0/8.4.1/adalib/libgnat-2020.dylib' (no such file), '/Users/../../..//opt/gnat/2020/lib/libgnat-2020.dylib' (no such file), '/usr/local/lib/libgnat-2020.dylib' (no such file), '/usr/lib/libgnat-2020.dylib' (no such file, not in dyld cache)
zsh: abort      ./fcs_software

关于为什么会发生这种情况以及如何解决它有什么想法吗?

谢谢,

罗伯特


如果需要,这里是我的设置的详细信息:

  1. 项目结构:
.
├── FCS_Middleware
│   ├── dist
│   │   ├── fcsm-math.ads
│   │   ├── fcsm-math.ali
│   │   ├── fcsm.ads
│   │   ├── fcsm.ali
│   │   └── libfcs_middleware.dylib
│   ├── fcs_middleware.gpr
│   └── src
│       ├── fcsm
│       │   ├── fcsm-math.adb
│       │   ├── hidden_package.adb
│       │   └── hidden_package.ads
│       ├── fcsm-math.ads
│       └── fcsm.ads
└── FlightControlSoftware
    ├── dist
    │   ├── fcs_software **executable**
    │   └── lib
    │       ├── fcsm-math.ali
    │       ├── fcsm.ali
    │       └── libfcs_middleware.dylib
    ├── fcs_middleware.gpr
    ├── flight_control_software.gpr
    ├── include
    │   ├── fcsm-math.ads
    │   └── fcsm.ads
    └── src
        └── main.adb

只有当我将

FlightControlSoftware/dist
文件夹移动到即我的下载文件夹时才会出现问题。执行
FlightControlSoftware/dist/fcs_software
有效。

  1. FCS_Middleware主工程文件
project FCS_Middleware is

    for Source_Dirs use ("src/**");
    for Object_Dir use ".obj";
    for Library_Dir use "dist";
    for Library_Src_Dir use "dist";
    for Library_Name use "fcs_middleware";
    for Library_Kind use "dynamic";

    for Library_Interface use ("FCSM", "FCSM.Math");

end FCS_Middleware;
  1. 飞控软件项目文件
with "fcs_middleware.gpr";

project Flight_Control_Software is

    for Source_Dirs use ("src/**");
    for Object_Dir use ".obj";
    for Exec_Dir use "dist";
    for Main use ("main.adb");

    package Binder is
        for Switches ("ada") use ("-Es");
    end Binder;

    package Builder is
        for Executable ("main.adb") use "fcs_software";
    end Builder;

end Flight_Control_Software;
  1. FCS包中的FCS_Middleware项目文件
project FCS_Middleware is
    for Source_Dirs use ("include");
    for Library_Name use "fcs_middleware";
    for Library_Dir use "dist/lib";
    for Library_Kind use "dynamic";
    for Externally_Built use "true";
end FCS_Middleware;
ada
1个回答
0
投票

使用

gnatls -v
查看编译器配置的搜索路径;请注意,首先搜索当前目录。

使用

gcc -dynamiclib
,它“使用 Darwin
libtool
命令生成动态库而不是可执行文件。”

使用绑定器开关

-shared
来“链接到共享 GNAT 运行时。”

使用

otool -L
“显示目标文件使用的共享库的名称和版本号”。这表明可执行文件期望在哪里找到共享库。

为什么我需要这个库? ada运行时库由

libgnat
提供;您可能还需要
libgnarl

这是跨其他 Mac 的便携式解决方案吗?一般来说,是的,但有一些注意事项:

  • 在下面的示例中,

    libgnat
    libgnarl
    都需要
    libSystem.B.dylib
    ,在最新版本的MacOS中是虚拟

  • 未来兼容性良好;倒退则不然;测试验证。

  • 检查您的实施附带的许可证,了解分发运行时库的详细信息。

$ otool -L $ADA_LIB/libgnat.dylib $ADA_LIB/libgnarl.dylib 
/opt/gcc-13.1.0/lib/gcc/x86_64-apple-darwin21/13.1.0/adalib/libgnat.dylib:
    @rpath/libgnat-13.dylib (compatibility version 0.0.0, current version 0.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)
/opt/gcc-13.1.0/lib/gcc/x86_64-apple-darwin21/13.1.0/adalib/libgnarl.dylib:
    @rpath/libgnarl-13.dylib (compatibility version 0.0.0, current version 0.0.0)
    @rpath/libgnat-13.dylib (compatibility version 0.0.0, current version 0.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)
© www.soinside.com 2019 - 2024. All rights reserved.