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,d44f5f5c83c371ab X-Google-Attributes: gid103376,public From: rou271@prb.net Subject: Re: Help interfacing Ada and C++ Date: 1997/06/26 Message-ID: <867328186.14061@dejanews.com>#1/1 X-Deja-AN: 252706639 References: <33A28715.1558@codenet.net> X-Http-User-Agent: Mozilla/2.0 (compatible; MSIE 3.02; Win32) X-Originating-IP-Addr: 208.139.81.8 () Organization: Deja News Usenet Posting Service X-Article-Creation-Date: Thu Jun 26 12:29:51 1997 GMT X-Authenticated-Sender: rou271@prb.net Newsgroups: comp.lang.ada Date: 1997-06-26T00:00:00+00:00 List-Id: In article <33A28715.1558@codenet.net>, Charlie Gage wrote: > > Greetings, > I have a need to interface Ada95 (specifically Gnat) with C++ (SPARC), > and am having some difficulty with it. I have read all the Gnat docs > and everything seems to work OK, except when I #include > in the C++ code and try to use anything like "cout". The Gnat linker > complains about an undefined symbol. If I #include and use > printf, everything works OK. Now, however I need to use cout and > other things in the iostream.h and fstream.h. I have used the > "with Interfaces.CPP" in the Ada code, but it does not seem to make > a difference. Are there any other libraries that I need to include > when linking with Gnat? Any help with this, or a pointer to more > information would be greatly appreciated. > > Thanks, > Charlie Gage > Email: cgage@codenet.net or charles.gage@lmco.com I'm not sure which way you are calling things - Ada from C++ or C++ from Ada, but here is an example of each using Visual C++ and ObjectAda: C++ calling Ada95 - test_int.ads : with interfaces.c; package test_int is procedure get_day(day: in out interfaces.c.int); pragma export (cpp, get_day, "get_day", "_get_day"); end test_int; test_int.adb: package body test_int is procedure get_day(day: in out interfaces.c.int) is today_ada : interfaces.c.int:=interfaces.c.int(1); begin day := today_ada; end get_day; end test_int; test_int.cpp: #include extern "C" void get_day ( int *); void main(){ int today = 4; cout << "C sez today is " << today << endl; get_day(&today); // If "<< endl;" is put on the end of this statement, it prints // address of endl?! cout << "Ada sez today is " << today; cout << endl; } Ada95 calling C++ - import_p.ads : ( Here is the mangled name I got from the C object.) with Interfaces.C; use Interfaces.C; package import_pkg is procedure import(num : in Int); pragma Import (Cpp, import, external_name => "?imported_function@@YAXH@Z"); end import_pkg; useimpor.adb : with import_pkg; with text_io; use text_io; procedure Use_Of_Import is begin import_pkg.import(5); end Use_Of_Import; imporfn.cpp #include void imported_function (int n) { cout << " I am now in the imported function " << n << endl; } I did not have to link with anything special to use cout. I don't know if this helps since you are using different compilers. I did use this with gnat calling Visual C++ also. Betty -------------------==== Posted via Deja News ====----------------------- http://www.dejanews.com/ Search, Read, Post to Usenet