Last active
April 20, 2020 06:32
-
-
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):
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
procedure Multiple_Exports.Main | |
is | |
procedure Foobar | |
with Import, | |
Convention => C, | |
External_Name => "foobar_c"; | |
begin | |
Foobar; | |
end Multiple_Exports.Main; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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