0

我正在尝试为 iOS 制作一个 Ada 库。但是,需要手动执行 Ada 细化。

我知道编译器可以生成一个初始化符号,以后可以导入和使用。但是,对于以下 GPR 定义,它不会生成(该nm命令未列出它)。命名应该<libname>init<libname>GPR 指令中定义的值相对应Library_Name

GPR 是按以下方式定义的(这是 windows/style -see DLL references-,但在 Mac 上为 iOS 生产时也存在问题):

project adalib is
    for Languages use ("Ada");
    for Source_Dirs use (project'Project_Dir & "./src");
    for Library_Kind use "static"; --"static" on iOS will produce a .a file
    for Library_Name use project'Name; -- will produce "libadalib.a"
    for Library_Dir use project'Project_Dir & "./lib";
    for Library_Src_Dir use project'Project_Dir & "./includes";
    -- define your favorite compiler, builder, binder, linker options
end adalib;

我想念它:如何产生那个符号?

4

1 回答 1

1

我找到了解决方案。我的 GPR 缺少这个简单的指令:

    for Library_Interface use ("mypackage"); -- put whatever packages you want to expose, without .adb/.ads since we're talking about packages

使用上面的指令,我可以通过命令找到adalibinit符号。nm当我在我的 ada 代码中导入它时,我也可以使用它,请参阅:

package body mypackage is
    procedure Init_My_Lib
    is
       -- I want to call elaboration;
       pragma import (C, ada_elaboration, "adalibinit");
    begin
       ada_elaboration;
       -- further code
    end Init_My_Lib;
-- rest of package

所以,完整的 GPR 应该是:

project adalib is
    for Languages use ("Ada");
    for Source_Dirs use (project'Project_Dir & "./src");
    for Library_Kind use "static"; -- will produce a .a file
    for Library_Name use project'Name; -- will produce "libadalib.a"

    for Library_Interface use ("mypackage"); -- <=== THIS IS HERE

    for Library_Dir use project'Project_Dir & "./lib";
    for Library_Src_Dir use project'Project_Dir & "./includes";
    -- define your favorite compiler, builder, binder, linker options
end adalib;
于 2017-06-28T16:57:21.240 回答