Re: How to declare Fortran subroutine in C++ compiler??

New Message Reply Date view Thread view Subject view Author view

ken sartor (sartor++at++bur.visidyne.com)
Mon, 23 Jun 1997 10:08:27 -0500


At 10:10 AM 6/22/97 -0400, Hansong Zhang wrote:
>> Hello,
>>
>> I have a math subroutine which is written by Fortran. I use C++
>> compiler to compile my Performer program. This math routine is part of my
>> main(). When I compile this mixed language program, I get a unresolved
"routine
>> name" error.
>>
>> I declare this math routine as "extern int simmain()" in main.c. I
>> compiled it by using f77, Fortran compiler. I put the simmain.o and -lF77,
>> -lU77, -lI77,-lisam, -lm in the CC command line. I also tried to switch the
>> location of simmain.o and main.o in the CC command line.
>>
>> Do I make any mistake? Or I forgot somethings else? I successed in
>> compiling the C and Fortran mixed program. I realy need your help. I
will very
>> appreciate for you help. Have a nice day.
>>
>> p/s : my OS is IRIX 6.2
>>
>
>Try to declare the fortran function as
>extern "C" {
> int simmain();
>}
>which prevents CC from generating signature for the function name and
>making it differnt from the one in your fortran object file.
>
>Besides (and if the above suggestion doesn't work), you can use the f2c
>package to translate the fortran program to C. I used to use it for big
>fortran math routines and it worked really well. f2c's available from
>netlib.
>
>hope this helps,
>Hansong

Here is how i have done it in the past...

First declare the function...

extern "C" {
extern void ttest_(int* T1, int* T2, float* T3);
}

Then call the function...

        ttest_(&t1, &t2, &t3);

Good luck. (Note that in this case, i am passing the addresses
of the variables. This is to allow the returning values to
be passed back into the calling routine. If this were not
necessary, then of course you could just pass in the values.)

ken
=======================================================================
List Archives, FAQ, FTP: http://www.sgi.com/Technology/Performer/
            Submissions: info-performer++at++sgi.com
        Admin. requests: info-performer-request++at++sgi.com


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:55:29 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.