From: rou271@prb.net
Subject: Re: Help interfacing Ada and C++
Date: 1997/06/26
Date: 1997-06-26T00:00:00+00:00 [thread overview]
Message-ID: <867328186.14061@dejanews.com> (raw)
In-Reply-To: 33A28715.1558@codenet.net
In article <33A28715.1558@codenet.net>,
Charlie Gage <cgage@codenet.net> 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 <iostream.h>
> in the C++ code and try to use anything like "cout". The Gnat linker
> complains about an undefined symbol. If I #include <stdio.h> 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 <iostream.h>
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 <iostream.h>
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
prev parent reply other threads:[~1997-06-26 0:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-06-14 0:00 Help interfacing Ada and C++ Charlie Gage
1997-06-14 0:00 ` Robert Dewar
1997-06-15 0:00 ` Jerry van Dijk
1997-06-26 0:00 ` rou271 [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox