calling C library routines

calling C library routines

I am writing a program with a mandate to use nothing but Fortran. However, I need to call the C library routines mmap, msync, and munmap.

The code is all in place and compiles fine but when I compile I get unresolved synbol errors for mmap_, msync_, and munmap_. Aparently, the compiler is trying to tack on underscore onto the function names. If I compile with -nus I get unresolved symbols for all the external fortran routines I am calling but none for the C library functions.

Is there a way to tell the compiler to not tack on the underscore for certain functions?

Just in case you are interested, I did define an interface for mmap. Here is how it looks:

INTERFACE
FUNCTION MMAP(start, length, prot, flags, fd, offset) RESULT(Address)
INTEGER,INTENT(IN)::start,length,prot,flags,fd,offset
INTEGER::Address
END FUNCTION MMAP
END INTERFACE

I did not define an interface for msync or munmap. I am compiling with only the -g option.

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

Message Edited by tim18 on 08-25-2004 03:46 PM

Hello,

There is the "-nus,filename" option you could use. You create a text file (I will use as an example the name nounderscore.txt) and list in it the functions that you don't want to have an underscore appended. At compile time you add the switch "-nus,nounderscore.txt" to the compiler flags.

In your case the nounderscore.txt file would look like that:

--- Begin nounderscore.txt ---
mmap
msync
munmap
--- End nounderscore.txt ---

I hope that this will help,

Ioannis

tcprince wrote:
Don't forget to deal with arguments passed by value, whether you write C wrapper functions, or attempt the DEC$ ATTRIBUTES declarations. Either way, you aren't strictly within the "fortran only" guideline.

tcprince, I am new to Fortran. What is "DEC$ ATTRIBUTES"?

iev, the -nus,filename seemed to do the same thing as -nus by itself. Do you know if that option is supported by ifort version 8.0.039?

Hello again,

I have succesfully used the -nus,filename option with version 7.1 of the compiler. I installed version 8.0 and looked at the documentation. Although the option is still there, the description is a little bit cryptic to me and certainly totally different than the description for version 7.1. I am puzzled about this. Are you sure that the compiler finds the text file you create?

Ioannis

tcprince wrote:
Don't forget to deal with arguments passed by value, whether you write C wrapper functions, or attempt the DEC$ ATTRIBUTES declarations. Either way, you aren't strictly within the "fortran only" guideline.

yay!

Thanks tcprince!!

This did the trick:
!DEC$ ATTRIBUTES C, ALIAS:'munmap' :: MUNMAP

It links!! Woohoo!

:)

Compiler directives are fine, as long as they are in the .f90 file.

iev@hpclab.ceid.upatras.gr wrote:
Hello again,

I have succesfully used the -nus,filename option with version 7.1 of the compiler. I installed version 8.0 and looked at the documentation. Although the option is still there, the description is a little bit cryptic to me and certainly totally different than the description for version 7.1. I am puzzled about this. Are you sure that the compiler finds the text file you create?

Ioannis

I may have made a typo. I'll double-check. I looked at the man page and did not see the option described there. What doc were you looking in?

EDIT: ok, I found it in for_ug1.pdf

Man, cryptic is right. I wish the gave an example. It may mean a you can specify a specific fortran file. If thats true and I wanted it to not add an underscore to the end of my string routines I could specify "-nus,Strings.f90". I may be wrong.

Message Edited by john.fluharty on 01-21-2004 06:08 AM

I was looking at the documents under the /opt/intel_fc_80/doc directory and specifically the for_ug1.pdf file. The above directory is the default installation directory. If you installed the compiler somewhere else change the /opt/intel_fc_80 part accordingly.

I hope that this helps. I am also frequently linking Fortran and C object files together and therefore I am very interested to solve this.

Ioannis

Leave a Comment

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