From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.unit0.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Linking Ada to C++ Overloaded Functions and Methods Date: Sat, 7 Apr 2018 22:05:22 +0300 Organization: Tidorum Ltd Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net CzYZUFPxTpE7p3PXGH0iKweN+ILpRHnaHeJOSNJ1luVkpxEG/Q Cancel-Lock: sha1:FhCAumIBO8W3tygpWkh9wuD0lIQ= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 In-Reply-To: Xref: reader02.eternal-september.org comp.lang.ada:51389 Date: 2018-04-07T22:05:22+03:00 List-Id: On 18-04-07 21:35 , Ron Wills wrote: > I know that both Ada and C++ can overload functions and methods. The problem I'm having is when I'm trying to link Ada to overload C++ functions. I know I could use different Ada names, but if it's possible to keep the same names in Ada it would save a lot of re-coding. > > An example is from the FLTK library. The "draw_box" method from the Fl_Widget class is overloaded and I get the following from g++ -fdump-ada-spec. > > procedure draw_box (this : access constant Fl_Widget'Class); > pragma Import (CPP, draw_box, "_ZNK9Fl_Widget8draw_boxEv"); > > procedure draw_box > (this : access constant Fl_Widget'Class; > t : Fl_Enumerations_H.Fl_Boxtype; > c : Fl_Enumerations_H.Fl_Color); -- /usr/include/Fl/Fl_Widget.H:181 > pragma Import (CPP, draw_box, "_ZNK9Fl_Widget8draw_boxE10Fl_Boxtypej"); > > The C++ name mangling works to uniquely identify the C++ methods, but the compiler is choking on the Ada names as already being declared. > > fl_fl_widget_h.ads:171:07: entity "draw_box" was previously imported > fl_fl_widget_h.ads:171:07: (pragma "Import" applies to all previous entities) > fl_fl_widget_h.ads:171:07: import not allowed for "draw_box" declared at line 164 > fl_fl_widget_h.ads:181:07: entity "draw_box" was previously imported > fl_fl_widget_h.ads:181:07: (pragma "Import" applies to all previous entities) > fl_fl_widget_h.ads:181:07: import not allowed for "draw_box" declared at line 167 > > Is there a way to use overloaded Ada names with C++ or do I need to find a unique Ada name for every C++ overload method? > I would try to change the pragma Imports into aspects, something like this: procedure draw_box (....) with Import, Convention => CPP, Link_Name => "_ZNK9Fl_Widget8draw_boxE10Fl_Boxtypej"; Aspects are syntactically tied to the subprogram declaration in which they occur, so overloaded subprograms with the same identifier can be given different aspect values, unlike for pragma Import. Note that I'm not fully sure if you should use the Link_Name aspect or the External_Name aspect. The C++ identifiers given in the pragma Imports are External_Name values, but I think they are also Link_Name values. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .