Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28996 Discussions

Linux F90 .so build and execution in a mixed-language environment

jimp
Beginner
445 Views

This is a pre-sales question. Our group has been provided with Fortran 90 source library to which we must provide C bridge routines to certain entry points. We will then build the Fortran 90 and C into a single shared object on Linux Redhat 4.0. The shared object's Cbridgeroutineswill then be invoked via the dlopen() and dlsym() functions by another application.

We do not have the optionof linking the Fortran 90 and C bridges statically into the main application.

The main application which will load the .so file and call the entry point has a restriction that the called routine, the bridge in this case,must havethe equivalent of aC prototype of (int argc, char *argv[]). Our C bridge would then recast the pointers and pass them to Fortran.

We are currently attempting to solve this problem using a competing company's Fortran compiler. We can successfully build the .so file and invoke the C bridge, but at the point where the Fortran 90 is called, a stack error results. We suspect it's because the Fortran runtime is not being loaded and we've been unable to locate anything in their documentation that might provide us with direction for initializing the runtime.Thecompany's technical support has not been able to solve the problem.

We are interested in knowing if anyone has built and used such a thing on Linux using Intel Fortran. We have been successful using this calling mechanism on WinXP by constructing a DLL using an evaluation license for Intel Fortran and MS Visual Studio.

We would be open to switching Fortran compilers if we could be assured that we would be likely to meet with success. We can also provide short example C and F90 code that exemplifies the problem (a total of only 12 KB) if anyone wants to have a go.

Thanks,

Jim P.

0 Kudos
2 Replies
Steven_L_Intel1
Employee
445 Views
I think this should work. We do supply a for_rtl_init_ and for_rtl_finish_ routine which is to be called from C if the main program is not Fortran. fort_rtl_finish_ closes files and may not be required in your case. These are documented.
0 Kudos
retromoly
Beginner
445 Views
I'm working on something similar at the moment.

Are you passing structures by reference in these C bridge functions?? Or using common blocks between the two? If so, it could very well be a memory alignment issue.

The C and FORTRAN compilers don't neccesarily align things the same in memory. There are compiler options to tweak this stuff on both sides. What has worked for me recently is using "-align none" on the intel fortran side - but as you may see in another recent post by me, this isn't without some issues of its own.
0 Kudos
Reply