comp.lang.ada
 help / color / mirror / Atom feed
* Re: importing fortran routines to GNAT
  1997-02-21  0:00 importing fortran routines to GNAT Pasi J. Hakala
  1997-02-21  0:00 ` Robert Dewar
@ 1997-02-21  0:00 ` Joerg Rodemann
  1997-02-23  0:00   ` Robert Dewar
  1 sibling, 1 reply; 4+ messages in thread
From: Joerg Rodemann @ 1997-02-21  0:00 UTC (permalink / raw)



Pasi J. Hakala (pjh@msslac.mssl.ucl.ac.uk) wrote:
>    Here's what I've done (This is under OS/2 with g77, gcc 2.7... and
> emx 0.9c):
>       - gcc -c amain.adb   (no complaints)
>       - g77 -c subsum.f    (no complaints)
>       - gnatbind amain.ali  (no complaints) 
>       - gnatlink amain.ali subsum.o  
>          which results in 'cannot find object _subsum etc....

Hello Pasi!

I just tried your example under HP-UX10.10 (GNAT3.05, HP-f77) and SunOS 5.5.1
(Solaris 2.5??, Sun-f77). This lead to the following results:

   HP:  just working fine.
   Sun: linker complains about undefined symbol subsum_

It seem that the various compiler have different internal naming conventions
for functions. On the Sun platform I could solve the problem by using a
slightly different Import-statement:

>    procedure subsum(In1 : in Real; In2 : in Real ; Outsum : out Real);
>    pragma import(Fortran,subsum, "subsum_");

The third parameter is the name to be found in the object file as far as I
understand this materia. So in your case a

    pragma import(Fortran,subsum, "_subsum");

should work.

Hope this helps

Greetings 

George

--
Joerg 'George' Rodemann                      Erhard-Groezinger-Strasse 82
Department of Physics                                   D-89134 Blaustein
University of Ulm                                      Tel. (0731) 553319
e-mail:                                    rodemann@mathematik.uni-ulm.de




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

* importing fortran routines to GNAT
@ 1997-02-21  0:00 Pasi J. Hakala
  1997-02-21  0:00 ` Robert Dewar
  1997-02-21  0:00 ` Joerg Rodemann
  0 siblings, 2 replies; 4+ messages in thread
From: Pasi J. Hakala @ 1997-02-21  0:00 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 986 bytes --]

Hi!

I'm a sworn FORTRAN-programmer finally trying to learn a more
advanced language (ADA). Now, I still have lots of fortran
subroutines that I want to use, but somehow all the information
on how to do that in GNAT (3.05 I think) doesn't seem to apply
to me... :( 
      I've attached two files to this message: amain.adb is a
very simple main program that calls subsum.f (an even more simple
fortran subroutine). Now, HOW CAN I MAKE THE ADA MAIN
PROGRAM TO SEE THE SUBROUTINE???!!!
   Here's what I've done (This is under OS/2 with g77, gcc 2.7... and
emx 0.9c):
      - gcc -c amain.adb   (no complaints)
      - g77 -c subsum.f    (no complaints)
      - gnatbind amain.ali  (no complaints) 
      - gnatlink amain.ali subsum.o  
         which results in 'cannot find object _subsum etc....

    So can please someone help a poor astronomer on a way from 
    fortran to ADA....or otherwise I'll stick to fortran for
     another Hubble-time......

                   Cheers, Pasi

[-- Attachment #2: amain.adb --]
[-- Type: text/plain, Size: 489 bytes --]

with Text_Io; use Text_Io;
with Interfaces.Fortran; use Interfaces.Fortran;

procedure Amain is

   package Int_Io is new Integer_IO (Integer); use Int_Io;
   package Flt_Io is new Float_IO (Float); use Flt_Io;

   procedure subsum(In1 : in Real; In2 : in Real ; Outsum : out Real);
   pragma import(Fortran,subsum);

   i1,i2,ou : Real;

begin
   ou:=0.0;
   i1:=1.0;
   i2:=2.0;
--
--      Call the imported fortran routine
--
   subsum(i1,i2,ou);
   New_Line;
   Put(Float(ou));
end; 
\x1a

[-- Attachment #3: subsum.f --]
[-- Type: text/plain, Size: 114 bytes --]

        SUBROUTINE SUBSUM(IN1,IN2,OUT)
        REAL IN1,IN2,OUT
C
        OUT=IN1+IN2
        RETURN
        END
\x1a

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

* Re: importing fortran routines to GNAT
  1997-02-21  0:00 importing fortran routines to GNAT Pasi J. Hakala
@ 1997-02-21  0:00 ` Robert Dewar
  1997-02-21  0:00 ` Joerg Rodemann
  1 sibling, 0 replies; 4+ messages in thread
From: Robert Dewar @ 1997-02-21  0:00 UTC (permalink / raw)



Pasi asks

<<I'm a sworn FORTRAN-programmer finally trying to learn a more
advanced language (ADA). Now, I still have lots of fortran
subroutines that I want to use, but somehow all the information
on how to do that in GNAT (3.05 I think) doesn't seem to apply
to me... :(
      I've attached two files to this message: amain.adb is a
very simple main program that calls subsum.f (an even more simple
fortran subroutine). Now, HOW CAN I MAKE THE ADA MAIN
PROGRAM TO SEE THE SUBROUTINE???!!!>>


A couple of points. You are using some old version of GNAT but you did
not say on what machine. This is critical information. The current version
of GNAT is 3.10, and the current publically available version is 3.09 (you
mentioned 3.05). This may or may not be relevant to your problem, because
we still don't know what machine you are using.

In any case, this certainly seems like a bug in GNAT, what you wrote looks
perfectly correct. So if this problem persists using the latest version of
GNAT, you should send along a bug report to report@gnat.com. Be sure to
specify what machine you are using and what operating system (there are
many ports of GNAT).

That last request is something that everyone should pay attention to. When
reporting problems with GNAT it is very important to not only give the
version number, but also to state the machine and operating system, since
there are now over 30 versions of GNAT, and though for the most part you
will get identical results, there are cases of bugs which show up only on
one version and not another. Since the problem here is with the naming
of external symbols when done by default, it is clearly system dependent
(you could obviously fix your problem by using a third parameter to
the pragma Import that gave the proper external name, but it shuld be
chosen by default).

Finally, for general questions on GNAT, consider using the gnat chat mailing
list instead of, or at least in addition to, comp.lang.ada. There are many
knowledgable users of GNAT who can sometimes provide useful informal help
for those who do not have support from Ada Core Technologies. TO subscribe
to this list, send a subscribe message to chat-request@gnat.com.





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

* Re: importing fortran routines to GNAT
  1997-02-21  0:00 ` Joerg Rodemann
@ 1997-02-23  0:00   ` Robert Dewar
  0 siblings, 0 replies; 4+ messages in thread
From: Robert Dewar @ 1997-02-23  0:00 UTC (permalink / raw)



Joerg said

<<The third parameter is the name to be found in the object file as far as I
understand this materia. So in your case a

    pragma import(Fortran,subsum, "_subsum");

should work.>>

NO, that's wrong, the *fourth* parameter is the actual external name, so it
is better to write

    pragma Import (Fortran, subsum, Link_Name => "_subsum");

The third parameter is the external name, and should look exactly like
the name looks in Fortran, including using the proper case, but not
adding junk characters.

Sounds like there is a bug in some particular configuration of GNAT. This
should be reported to report@gnat.com (it is especially important in a
case like this to give precise versions of everything (GNAT, Fortran
compiler, operating system, machine).





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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-02-21  0:00 importing fortran routines to GNAT Pasi J. Hakala
1997-02-21  0:00 ` Robert Dewar
1997-02-21  0:00 ` Joerg Rodemann
1997-02-23  0:00   ` Robert Dewar

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