You could try adding the Export
and Convention => X
aspects to the package if you're using an Ada 2012 compiler; example:
Package K with Export, Convention => C_Plus_Plus is
Function A( Input_1, Input_2 : Integer ) return Integer;
End K;
This actually compiles, though since I don't have any C++ or C mixed-source projects to try this on I can't tell you if the results are strictly-speaking usable from the C++ side.
If that doesn't work, perhaps a better method would be to create a package especially for exporting the functions (and types) that will be used on the C++ side.
With
System,
Interfaces.C.Strings,
Interfaces.C.Pointers;
Package K with Convention => C_Plus_Plus is
-------------
-- TYPES --
-------------
Type CPP_Window_Handle is Private;
Subtype CPP_String is Interfaces.C.Strings.chars_ptr;
--------------
-- MODULES --
--------------
Package UI_Module is
Procedure Set_Title( Window : CPP_Window_Handle; Text : CPP_String )
with Export;
End UI_Module;
Private
Package STUB_TYPES is
Type Window is tagged null record;
End STUB_TYPES;
Use STUB_TYPES;
Type CPP_Window_Handle is not null access Window'Class
with Convention => C_Plus_Plus, Size => Interfaces.C.int'Size;
End K;
Implemented as:
Package Body K is
Package STUB_FUNCTIONS is
Procedure Set_Window(Object : in out STUB_TYPES.Window'Class; Text : String) is null;
--'
End STUB_FUNCTIONS;
Package Ada_Dependencies renames STUB_FUNCTIONS;
Package Body UI_Module is
Procedure Set_Title( Window : CPP_Window_Handle; Text : CPP_String ) is
function Value (Item : CPP_String) return Interfaces.C.char_array
renames Interfaces.C.Strings.Value;
function Convert(Item : Interfaces.C.char_array;
Trim_Nul : Boolean := True) return String
renames Interfaces.C.To_Ada;
Begin
Ada_Dependencies.Set_Window(
Object => Window.all,
Text => Convert( Value( Text ) )
);
End Set_Title;
End UI_Module;
End K;