comp.lang.ada
 help / color / mirror / Atom feed
* Re: Help interfacing Ada and C++
  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
  2 siblings, 0 replies; 4+ messages in thread
From: Robert Dewar @ 1997-06-14  0:00 UTC (permalink / raw)



Charlie says

<<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.>>


YOu need to have all the correct CPP pragmas in your code, not something
that is easy to do by hand (for example, you need to know the proper mangled
names for all the C++ routines you want to call -- probably you did not do
that properly by the sound of it). Try asking this question on that 
chat@gnat.com list, maybe someone there can help you. We do have at least
one customer who has successfully interfaced GNAT and C++ on Solaris.

Robert Dewar
Ada Core Technologies





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Help interfacing Ada and C++
@ 1997-06-14  0:00 Charlie Gage
  1997-06-14  0:00 ` Robert Dewar
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Charlie Gage @ 1997-06-14  0:00 UTC (permalink / raw)



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




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Help interfacing Ada and C++
  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
  2 siblings, 0 replies; 4+ messages in thread
From: Jerry van Dijk @ 1997-06-15  0:00 UTC (permalink / raw)



>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.

you need to link in the code for iostream with the C++ module, like
-lstdcpp.

--

-- Jerry van Dijk  | Leiden, Holland
-- Consultant      | Team Ada
-- Ordina Finance  | jdijk@acm.org




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Help interfacing Ada and C++
  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
  2 siblings, 0 replies; 4+ messages in thread
From: rou271 @ 1997-06-26  0:00 UTC (permalink / raw)



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




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1997-06-26  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox