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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 2002:a24:41a8:: with SMTP id b40-v6mr12014126itd.18.1523131656818; Sat, 07 Apr 2018 13:07:36 -0700 (PDT) X-Received: by 2002:a9d:3286:: with SMTP id u6-v6mr336946otb.13.1523131656288; Sat, 07 Apr 2018 13:07:36 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!paganini.bofh.team!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!u184-v6no962162ita.0!news-out.google.com!15-v6ni419itg.0!nntp.google.com!u184-v6no962157ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 7 Apr 2018 13:07:36 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=24.72.55.22; posting-account=sfUYLwoAAADgN4x5cQtEVb7ua7QwdFn4 NNTP-Posting-Host: 24.72.55.22 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <959c633f-237d-47ea-88ff-4ad29faeb6c7@googlegroups.com> Subject: Re: Linking Ada to C++ Overloaded Functions and Methods From: Ron Wills Injection-Date: Sat, 07 Apr 2018 20:07:36 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:51390 Date: 2018-04-07T13:07:36-07:00 List-Id: On Saturday, April 7, 2018 at 1:05:24 PM UTC-6, Niklas Holsti wrote: > On 18-04-07 21:35 , Ron Wills wrote: > > I know that both Ada and C++ can overload functions and methods. The pr= oblem 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 sa= me 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 t= he 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 ent= ities) > > fl_fl_widget_h.ads:171:07: import not allowed for "draw_box" declared a= t 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 ent= ities) > > fl_fl_widget_h.ads:181:07: import not allowed for "draw_box" declared a= t line 167 > > > > Is there a way to use overloaded Ada names with C++ or do I need to fin= d a unique Ada name for every C++ overload method? > > >=20 > I would try to change the pragma Imports into aspects, something like thi= s: >=20 > procedure draw_box (....) > with Import, > Convention =3D> CPP, > Link_Name =3D> "_ZNK9Fl_Widget8draw_boxE10Fl_Boxtypej"; That worked perfectly! Thanks! > Aspects are syntactically tied to the subprogram declaration in which=20 > they occur, so overloaded subprograms with the same identifier can be=20 > given different aspect values, unlike for pragma Import. >=20 > Note that I'm not fully sure if you should use the Link_Name aspect or=20 > the External_Name aspect. The C++ identifiers given in the pragma=20 > Imports are External_Name values, but I think they are also Link_Name=20 > values. >=20 > --=20 > Niklas Holsti > Tidorum Ltd > niklas holsti tidorum fi > . @ .