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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9affc48dedad5655 X-Google-Attributes: gid103376,public From: "Samuel A. Mize" Subject: Re: Export in generic packages Date: 1997/05/19 Message-ID: <3380BC29.41C6@magellan.bgm.link.com>#1/1 X-Deja-AN: 242467099 References: <5lpm7e$gq7$1@luna.ffi.no> Organization: PSI Public Usenet Link Newsgroups: comp.lang.ada Date: 1997-05-19T00:00:00+00:00 List-Id: Rune Wemberg wrote: > I am trying to use the pragma Export in a generic > package for exporting an Ada procedure to C. Been there, done that, it's a minor pain. Use the "Convention" pragma so your generic procedure can be properly called by C. GNAT requires an exported procedure to be an externally visible procedure of a library-level package. So, you will define a library-level package that exports the procedure. Instantiate the generic in that package, and use a renaming-as-body to make the exported procedure equivalent to the instantiation. Here's a concrete example, that compiles and links with GNAT. -- export_me.ads -- generic function Export_Me return integer; pragma Convention (C, Export_Me); -- export_me.adb -- function Export_Me return integer is begin return 1776; end Export_Me; -- exporter.ads -- package Exporter is function C_Export_Me return integer; pragma Export (C, C_Export_Me, "export_me"); end Exporter; -- exporter.adb -- with Export_Me; package body Exporter is function Export_This_One is new Export_Me; function C_Export_Me return integer renames Export_This_One; end Exporter; /* import_it.c */ #include extern int export_me(); int main () { printf ("%d\n", export_me()); } Now: % gcc -c importer.adb % gcc import_it.c exporter.o -o import_it % import_it 1776 Samuel Mize Rune Wemberg wrote: > > Hello! > > I am trying to use the pragma Export in a generic > package for exporting an Ada procedure to C. The > gnatcompiler give me the message: > > "internal entity cannot be exported" > > The source looks like this: > > generic > -- Something here... > package Generic_Pack > > procedure My_Proc(Item : in Float ; > AnotherItem : out Float ; > ThirdItem : out Float) ; > pragma Export(C, My_Proc, "my_proc"); > > end Generic_Pack; > > If I try to use pragma Export outside the generic > package, I get the message: > > "pragma EXPORT argument must be in same declarative part" > > Is it not possible to export procedures from generic packages, > or instantions of theese? > > -- > Rune Wemberg > ruw@ffi.no -- Samuel Mize (817) 619-8622 "Team Ada" -- Hughes Training Inc. PO Box 6171 m/s 400, Arlington TX 76005