Skip to content

Instantly share code, notes, and snippets.

@egilhh
Last active April 20, 2020 06:32
Show Gist options
  • Save egilhh/ff0e4ffd8184e85dc4865194977f3185 to your computer and use it in GitHub Desktop.
Save egilhh/ff0e4ffd8184e85dc4865194977f3185 to your computer and use it in GitHub Desktop.
Ada can't export an entity more than once, but the linker might be able to create aliases, for GNAT/GCC this works (at least on my laptop):
Build instructions:
> gcc -c foobar.c -o foobar.o
> gnatmake multiple_exports-main.adb -largs foobar.o -Wl,--defsym=baz_ada=bar_ada,--defsym=qux_ada=bar_ada
extern void bar_ada(int);
extern void baz_ada(int);
extern void qux_ada(int);
void foobar_c()
{
bar_ada(1337);
baz_ada(42);
qux_ada(420);
}
procedure Multiple_Exports.Main
is
procedure Foobar
with Import,
Convention => C,
External_Name => "foobar_c";
begin
Foobar;
end Multiple_Exports.Main;
with Ada.Text_IO;
package body Multiple_Exports is
procedure Bar( P : Interfaces.C.int )
is
begin
Ada.Text_IO.Put_Line("Bar" & P'Image);
end Bar;
end Multiple_Exports;
with Interfaces.C;
package Multiple_Exports is
procedure Bar( P : Interfaces.C.int )
with Export,
Convention => C,
External_Name => "bar_ada";
end Multiple_Exports;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment