Board index » cppbuilder » calling fortran from C++ Builder 5.5

calling fortran from C++ Builder 5.5


2005-12-17 05:29:00 AM
cppbuilder71
I need to call a fortran subroutine (ADS optimization code) from C code, and
I am having some trouble compiling. When I try to do so, I get an error
stating the following:
"Unresolved external '_ADS' referenced from ctopt.obj"
Any suggestions on what this means?
What is the proper way to call fortran subroutines using Borland C++ Builder
5.5?
Currently I am calling it with ADS(......).
Thanks.
Mike
 
 

Re:calling fortran from C++ Builder 5.5

Mike S wrote:
Quote
I need to call a fortran subroutine (ADS optimization code) from C code, and
I am having some trouble compiling. When I try to do so, I get an error
stating the following:

"Unresolved external '_ADS' referenced from ctopt.obj"
Well, first, did you include the fortran obj or lib in the link
command?
If you did, then you need to find out the exact name of the function
as it appears in the obj or lib. Use TLIB or TDUMP to find out.
Once you know the true name of the function, you can futz with
underline, capitalization, and other name mangling issues.
 

Re:calling fortran from C++ Builder 5.5

"Bob Gonder" < XXXX@XXXXX.COM >wrote in message
Quote
Mike S wrote:

>I need to call a fortran subroutine (ADS optimization code) from C code,
>and
>I am having some trouble compiling. When I try to do so, I get an error
>stating the following:
>
>"Unresolved external '_ADS' referenced from ctopt.obj"

Well, first, did you include the fortran obj or lib in the link
command?

If you did, then you need to find out the exact name of the function
as it appears in the obj or lib. Use TLIB or TDUMP to find out.

Once you know the true name of the function, you can futz with
underline, capitalization, and other name mangling issues.

Ok, I'm not sure if I've done this properly; however, I think I'm on the
right track.
I used TLIB to extract the obj files from the fortran lib file. I also ran
tdump and all references to the subroutines and functions are with capital
letters without underscores.
However, now when I try to link in all the obj files (both c and fortran), I
get an error stating the following:
Fatal: Unsupported 16-bit segment(s) in module ads12.for
Any suggestions?
Thanks again for the help.
Mike
 

{smallsort}

Re:calling fortran from C++ Builder 5.5

Mike S wrote:
Quote
Fatal: Unsupported 16-bit segment(s) in module ads12.for

Any suggestions?
Well, 2 ways to go about it.
1) Use a 32bit Fortran compiler.
2) Use a 16bit C compiler.
The third way is called thunking and I never figured that out.
Going between 16 and 32 bit compiled code is extreemely tricky as the
16bit code expects to be working with AX by default while the 32bit
expects EAX to be default, and Segment registers are different from
Selector registers, even though they are the same register, and
addresses are 16 instead of 32 bits, so everything must be translated.
Very hairy.