- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try the directive with !DEC$ instead of !DIR$. I am told that !DIR$ is not recognized for ATTRIBUTES.
Steve
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Martyn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
try compiling the gnu stuff with -fno_second_underscore
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page