Linking to a C library (but has double underscores)

Linking to a C library (but has double underscores)

(cross posted from C++ forum -- sorry if you happen to browse both)

I have run into the infamous double-underscore issue.

I have a library that is written in C and a program that must link with that library written in Fortran 90. The ifort compiler insists on trying to link using single underscore suffixes for the functions it is using from the C library. Originally I used gcc to compile the C library but it produced double underscores. I have tried to compile the C library using icc but I still get double underscores as symbols. Any ideas how I can get ifort to link with double underscores or get icc to not create double underscores?

Thank you,

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I don't see why your C library would produce double underscores unless it was coded that way. It sounds like it may have been designed to link with g77-compiled code, which by default produces symbols with a double underscore.

The Intel Fortran compiler does not have a globaloption to produce symbols with double underscores. (This might mislead users into thinking it was compatible with g77 compiled objects, which it is not, the runtime libraries are very different). You can redefine individual symbols using the attributes directive, e.g.

!DIR$ ATTRIBUTES ALIAS:'newname__' :: oldname

This is discussed in the User's Guide, along with other aspects of mixed language programming and calling conventions. But it might be that a global edit of your C code would be simpler...


Leave a Comment

Please sign in to add a comment. Not a member? Join today