Calling C procedures from Fortran

Calling C procedures from Fortran

I am trying to call C procedures on the GNU Scientific Library (gsl) from a Fortran code but without success: the linker always complains about the missing trailing underscore on the routine name.
Is there any way to modify the default compiler/linker behavior of expecting a trailing underscore on those procedures?
I've tried to define an interface for the gsl procedures ( with:
!DIR$ ATTRIBUTES C, ALIAS: 'name_without_underscore' ::gsl_routine _name) but without success.

Thank you

7 帖子 / 0 全新
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项

I am having a similar problem. I am not able to call the c procedures compiled with gcc compiler. I am guessing this is because of the incompatibility of the binary/oject files produced by GNU c compiler and ifc compiler. Do I make sense? have you figured out what ur problem was??

Try the directive with !DEC$ instead of !DIR$. I am told that !DIR$ is not recognized for ATTRIBUTES.

Steve

Steve - Intel Developer Support

Sorry this may have nothing to do with the earlier posts.
This is the problem I am having.
I have one c file and a lot of Fortran files. I compile the c file using the gcc Ver2.96 and the Fortran file using ifc. When I go to link the files, all the c procedure I am calling in Fortran show up as an error "undefined reference to __".

Is there a flag I can use or am I doing something wrong here? I have refereed to the user guide about this issue and I am following the guidelines for calling C procedures.

You might try using the nm utility to check the symbols being generated on both C and Fortran sides. If they don't match, you can either change the function names in C, or use the !DEC$ ATTRIBUTES ALIAS directive in Fortran as discussed above. You also need to be aware of the different conventions for passing arguments in C and Fortran, as discussed in the User's Guide.

Martyn

try compiling the gnu stuff with -fno_second_underscore

I think that even if you sort out the underscore issues, calling GSL directly from fortran is unlikely to work due to the way the arguments to the functions are passed. In fortran they are always passed by reference (pointers). The usual way of merging a C function with another language is to write a small 'wrapper' function in C. This includes the underscore in the name and pointer types for the arguments. The wrapper is then called from fortran (without the underscore). For example
Fortran: INTEGER I,J ... CALL WRAP(I,J)
C: void wrap_(integer* i, integer* j){ *j = gsl_something(*i); }
More info can be found at
http://earth.leeds.ac.uk/~ash/aco/freesoftware.html

发表评论

登录添加评论。还不是成员?立即加入