comp.lang.ada
 help / color / mirror / Atom feed
* Interfacing ADA to C++ classes with parameters
@ 2002-04-03 12:46 John Haddon
  2002-04-03 13:53 ` Sergey Koshcheyev
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: John Haddon @ 2002-04-03 12:46 UTC (permalink / raw)




Dear All,

I'm having a problem writing an interface to a C++ class in which I want to
pass a parameter in addition to the object. I attach the package spec, the
main program and the C header file. The interface compiles and links with
the main program EXCEPT for TEST_INT_RET. On linkage, the following error is
given:

./ex6d_main.o: In function `ex6d_main__dispatch':
C:/PROGRA~1/GNAT/Examples_jfh/ex6d_main.adb:25: undefined reference to
`A::test_int_param(void)'

Why is this trying to refer to A::test_int_param(void) and not
A::test_int_param(integer,void)?

If the line calling test_int_param is omitted then the program links and
runs satisfactorily. I suspect that the problem is in the interface or
import function pragma parameters.

I am using Gnat 3.14p for Windows NT and GCC 2.95.3-5 for mingw as the C++
compiler. This examples is based upon EX6 in the GNAT documentation.

Any suggestions?

Many thanks in advance,


John

-----extract from souorce codes

package Ex6d_If is

   package A_Class is
      --
      --   Translation of C++ class A
      --

      type A is tagged
         record
            O_Value : Integer                   := 123;
            A_Value : Integer;                          -- := print(10);
            Vptr    : Interfaces.Cpp.Vtable_Ptr;
         end record;

      pragma Cpp_Class (Entity => A);
      pragma Cpp_Vtable (
         Entity      => A,
         Vtable_Ptr  => Vptr,
         Entry_Count => 7);

      --   Member Functions


      procedure Non_Virtual (This : in     A'Class );
      pragma Import (Cpp, Non_Virtual, "non_virtual__1A");
      pragma import_procedure (non_virtual,"non_virtual__1A",(A'class));


      function test_int_ret(This : in     A'Class)
      return integer;
      pragma Import (Cpp, test_int_ret, "test_int_ret__1A");

      function test_int_param(
            X    : in     integer;
            This : in     A'Class)
      return integer;
      pragma interface (Cpp, test_int_param);
-- IS THE FOLLOWING LINE CORRECT?
      pragma import_function(test_int_param,"
test_int_param__1A",(integer,A'Class),(integer));


      procedure Overridden (
            This : in     A );
      pragma Cpp_Virtual (Overridden,
         Vtable_Ptr  => Vptr,
         Entry_Count => 2);
      pragma Import (Cpp, Overridden, "overridden__1A");


      procedure Not_Overridden (
            This : in     A );
      pragma Cpp_Virtual (
         Entity      => Not_Overridden,
         Vtable_Ptr  => Vptr,
         Entry_Count => 4);

      pragma Import (Cpp, Not_Overridden, "not_overridden__1A");


      procedure My_Overridden (
            This : in     A );
      pragma Cpp_Virtual (
         Entity      => My_Overridden,
         Vtable_Ptr  => Vptr,
         Entry_Count => 6);--,      --  long form

      pragma Import (Cpp, My_Overridden, "my_overridden__1A");

      function Constructor return A'Class;
      pragma Cpp_Constructor (Entity => Constructor);
      pragma Import (Cpp, Constructor, "__1A");

   end A_Class;

end Ex6d_If;


--------------------------------
ex6d_main.adb ---------------------------------
with gnat.io;use gnat.io;
with ex6d_if;
procedure ex6d_main is

   use ex6d_if;
   use ex6d_if.A_Class;


   A_Obj : A_Class.A;

   procedure Dispatch (Obj : A_Class.A'Class) is
      x,y : integer := 98;
   begin
      put_line("In dispatch");
      put_line("calling non-virtual");
      Non_virtual (Obj);
      put_line("calling test_int_ret");
      x := test_int_ret(Obj);
      put("X=");put(x);new_line;
      put_line("calling test_int_param");
      x := test_int_param(y,Obj);
      put("X=");put(x);new_line;
      put_line("Calling overriden");
      Overridden (Obj);
      put_line("calling not_overridden");
      Not_Overridden (Obj);
      put_line("Calling my_overriden");
      my_Overridden (Obj);
   end Dispatch;

begin
   put("in ex6d_main");
   Dispatch (A_Obj);
end ex6d_main;



---- C Header file

class Origin {
 public:
  int o_value;
};

class A : public Origin {
 public:
  void    non_virtual (void);
  int     test_int_ret (void);
  int     test_int_param (int X);
  virtual void overridden (void);
  virtual void not_overridden (void);
  virtual void my_overridden (void);
  A();
  int   a_value;
};

________________________________________________________________


Dr. John F. Haddon, QinetiQ Fellow,

Centre for Robotics and Machine Vision,
X107 Building, Room 1032,
QinetiQ, Cody Technology Park, Farnborough, Hampshire, GU14 0LX, UK
Email:  jf_haddon@QinetiQ.com  Tel: 01252 395528; Fax: 01252 393942

Visiting Senior Fellow, CVSSP, University of Surrey.
Honorary Visiting Fellow, PANN, University of Exeter.
________________________________________________________________

The Information contained in this Email and any subsequent correspondence is
private and is intended solely for the intended recipient(s). For those
other than the recipient any disclosure, copying, distribution, or any
action taken or omitted to be taken in reliance on such information is
prohibited and may be unlawful.








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

end of thread, other threads:[~2002-04-05 19:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-03 12:46 Interfacing ADA to C++ classes with parameters John Haddon
2002-04-03 13:53 ` Sergey Koshcheyev
2002-04-04  8:18   ` John Haddon
2002-04-05 15:44     ` Robert Dewar
2002-04-05 19:15       ` Ted Dennison
2002-04-03 14:28 ` Mário Amado Alves
2002-04-03 19:01 ` Stephen Leake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox