Louis Etienne
Louis Etienne

Reputation: 1371

Compile unreferenced package with exported functions

In a project mixing Ada and C, I define and export Ada functions to be called in the C program. The compile chain is complex and I don't have a possibility to make any change to it but when I compile the project, the package containing the exported function and thus not called by any Ada code is completely left out by the compiler. This mean that the linker can't do its work as it missing external function.

For example this simple three files project :

Main.adb

with Ada.Text_IO;

procedure Main is
begin
   Ada.Text_IO.Put_Line ("Hello ada community");
end Main;

test.ads

package Test is

    procedure Hello
        with Export     => True,
             Convention => C,
             Link_Name  => "test_hello";

end Test;

test.adb

with Ada.Text_IO;

package body Test is

    procedure Hello is
    begin
        Ada.Text_IO.Put_Line ("Hello world");
    end Hello;

end Test;

When I compile my project, the package Test is ignored by the compiler. Is there a pragma to force the compiler to export the symbols and compile the package?

Upvotes: 3

Views: 145

Answers (1)

Louis Etienne
Louis Etienne

Reputation: 1371

Found the solution which was quite obvious. I just have to include the package in the main.adb file.

Upvotes: 3

Related Questions