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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4dcb75e86b22b9a6,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-04-03 04:45:00 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!newsfeed.icl.net!diablo.netcom.net.uk!netcom.net.uk!itchen!hamble.qinetiq.com!not-for-mail From: "John Haddon" Newsgroups: comp.lang.ada Subject: Interfacing ADA to C++ classes with parameters Date: Wed, 3 Apr 2002 13:46:20 +0100 Organization: QinetiQ Message-ID: NNTP-Posting-Host: 10.176.81.224 X-Trace: hamble.qinetiq.com 1017837833 29000 10.176.81.224 (3 Apr 2002 12:43:53 GMT) X-Complaints-To: postmaster@qinetiq.com NNTP-Posting-Date: Wed, 3 Apr 2002 12:43:53 +0000 (UTC) X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Xref: archiver1.google.com comp.lang.ada:22045 Date: 2002-04-03T13:46:20+01:00 List-Id: 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.