comp.lang.ada
 help / color / mirror / Atom feed
* import errors
@ 2004-03-07 18:55 Szymon Guz
  2004-03-07 19:10 ` Jeff C,
  2004-03-10  2:18 ` Stephen Leake
  0 siblings, 2 replies; 4+ messages in thread
From: Szymon Guz @ 2004-03-07 18:55 UTC (permalink / raw)


Hi,
I'm trying to make a binding to a dll library written in C++ and I'va 
got a problem. I have two types in one package and two procedures that 
are named the same:

type A;
type B is new A;

procedure A(this:A_Access);
procedure A(this:B_Access);

and now I want to import them from the dll library, but writing sth like 
  this:

pragma Import(C,A,"AAA");
pragma Import(C,A,"BBB");

generates some compiler errors, so I tried to do it in this way:
the body of the procedures looks like this:

procedure A(this:A_Access) is
   procedure THIS_A(this:A_Access);
   pragma Import(C,THIS_A,"AAA");
begin
   THIS_A(this);
end;

procedure A(this:B_Access) is
   procedure THIS_A(this:B_Access);
   pragma Import(C,THIS_A,"BBB");
begin
   THIS_A(this);
end;

I thought that it should work fine, but now I see that there is a 
compiler error which I don't undestand:

undefined reference to 'AAA'

So i've got two questions:
what do I do wrong that I cannot import the functions in the *.adb file 
and I can in the *.ads file ?
how can I import the functions ?



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

* Re: import errors
  2004-03-07 18:55 import errors Szymon Guz
@ 2004-03-07 19:10 ` Jeff C,
  2004-03-07 20:07   ` Szymon Guz
  2004-03-10  2:18 ` Stephen Leake
  1 sibling, 1 reply; 4+ messages in thread
From: Jeff C, @ 2004-03-07 19:10 UTC (permalink / raw)



"Szymon Guz" <guzo@stud.ics.p.lodz.pl> wrote in message
news:c2frbi$ac$1@nemesis.news.tpi.pl...
> Hi,
> I'm trying to make a binding to a dll library written in C++ and I'va
> got a problem. I have two types in one package and two procedures that
> are named the same:
>
> type A;
> type B is new A;
>
> procedure A(this:A_Access);
> procedure A(this:B_Access);
>
> and now I want to import them from the dll library, but writing sth like
>   this:
>
> pragma Import(C,A,"AAA");
> pragma Import(C,A,"BBB");
>
> generates some compiler errors, so I tried to do it in this way:
> the body of the procedures looks like this:
>
> procedure A(this:A_Access) is
>    procedure THIS_A(this:A_Access);
>    pragma Import(C,THIS_A,"AAA");
> begin
>    THIS_A(this);
> end;
>
> procedure A(this:B_Access) is
>    procedure THIS_A(this:B_Access);
>    pragma Import(C,THIS_A,"BBB");
> begin
>    THIS_A(this);
> end;
>
> I thought that it should work fine, but now I see that there is a
> compiler error which I don't undestand:
>
> undefined reference to 'AAA'
>
> So i've got two questions:
> what do I do wrong that I cannot import the functions in the *.adb file
> and I can in the *.ads file ?
> how can I import the functions ?


I am confused. At the end of your post you indicate that you cannot import
the functions in the .adb but
you can in the .ads file? But you don't show any examples of it. The one
error you are posting something (almost) specific for is
undefined reference to 'AAA' which if I am guessing correctly is not a
compiler error at all but is a linker error since it
can not find the symbol AAA.

1) Do you know for sure the linker name of the procedure you want is AAA?
2) Are you doing something (pragmas or linker switches to include a library
file that would contain this symbol?
3) You appear to be trying to bind to C++ (v.s. C) which is not very well
defined (i.e. There is no pragma Import(C++, X,X) in
the LRM). Have you done something in your C++ code to export the code to C
to make this rational?








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

* Re: import errors
  2004-03-07 19:10 ` Jeff C,
@ 2004-03-07 20:07   ` Szymon Guz
  0 siblings, 0 replies; 4+ messages in thread
From: Szymon Guz @ 2004-03-07 20:07 UTC (permalink / raw)


Jeff C, wrote:
> "Szymon Guz" <guzo@stud.ics.p.lodz.pl> wrote in message
> news:c2frbi$ac$1@nemesis.news.tpi.pl...
> 
>>Hi,
>>I'm trying to make a binding to a dll library written in C++ and I'va
>>got a problem. I have two types in one package and two procedures that
>>are named the same:
>>
>>type A;
>>type B is new A;
>>
>>procedure A(this:A_Access);
>>procedure A(this:B_Access);
>>
>>and now I want to import them from the dll library, but writing sth like
>>  this:
>>
>>pragma Import(C,A,"AAA");
>>pragma Import(C,A,"BBB");
>>
>>generates some compiler errors, so I tried to do it in this way:
>>the body of the procedures looks like this:
>>
>>procedure A(this:A_Access) is
>>   procedure THIS_A(this:A_Access);
>>   pragma Import(C,THIS_A,"AAA");
>>begin
>>   THIS_A(this);
>>end;
>>
>>procedure A(this:B_Access) is
>>   procedure THIS_A(this:B_Access);
>>   pragma Import(C,THIS_A,"BBB");
>>begin
>>   THIS_A(this);
>>end;
>>
>>I thought that it should work fine, but now I see that there is a
>>compiler error which I don't undestand:
>>
>>undefined reference to 'AAA'
>>
>>So i've got two questions:
>>what do I do wrong that I cannot import the functions in the *.adb file
>>and I can in the *.ads file ?
>>how can I import the functions ?
> 
> 
> 
> I am confused. At the end of your post you indicate that you cannot import
> the functions in the .adb but
> you can in the .ads file? But you don't show any examples of it. The one
> error you are posting something (almost) specific for is
> undefined reference to 'AAA' which if I am guessing correctly is not a
> compiler error at all but is a linker error since it
> can not find the symbol AAA.

Yea, sure, it was just a mistake: all the errors that I get are linker 
errors.

> 
> 1) Do you know for sure the linker name of the procedure you want is AAA?

I think so. I've checked that in the *.def file and what's more I can 
import it in the *.ads file, I haven't checked if it imports the 
function properly but there are no linker errors.

> 2) Are you doing something (pragmas or linker switches to include a library
> file that would contain this symbol?

I think that
pragma Linker_Options ("DLL.lib");
is enough

> 3) You appear to be trying to bind to C++ (v.s. C) which is not very well
> defined (i.e. There is no pragma Import(C++, X,X) in
> the LRM). Have you done something in your C++ code to export the code to C
> to make this rational?
> 

I try to use some classes from MFC42D.DLL and unfortunately this is all 
C++ and I cannot change that.



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

* Re: import errors
  2004-03-07 18:55 import errors Szymon Guz
  2004-03-07 19:10 ` Jeff C,
@ 2004-03-10  2:18 ` Stephen Leake
  1 sibling, 0 replies; 4+ messages in thread
From: Stephen Leake @ 2004-03-10  2:18 UTC (permalink / raw)
  To: comp.lang.ada

Szymon Guz <guzo@stud.ics.p.lodz.pl> writes:

> Hi,
> I'm trying to make a binding to a dll library written in C++ and I'va
> got a problem. I have two types in one package and two procedures that
> are named the same:
> 
> type A;
> type B is new A;
> 
> procedure A(this:A_Access);
> procedure A(this:B_Access);
> 
> and now I want to import them from the dll library, but writing sth
> like this:
> 
> pragma Import(C,A,"AAA");
> pragma Import(C,A,"BBB");
> 
> generates some compiler errors, 

One solution to this is to use a renames:

procedure AAA (This : A_Access);
pragma Import (C, AAA, "AAA");
procedure A (This : A_Access) renames AAA;

similarly for the other A.

-- 
-- Stephe




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

end of thread, other threads:[~2004-03-10  2:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-07 18:55 import errors Szymon Guz
2004-03-07 19:10 ` Jeff C,
2004-03-07 20:07   ` Szymon Guz
2004-03-10  2:18 ` Stephen Leake

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