Re: FW: How do I link a C function with a gFortran program

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sherman wrote:
I am trying to invoke a C function from a gFortran program.

The C function is called Read_Block and is intended to read one block from a
binary file that was not created by Fortran so does not have the fortran
header and footer on each block.

Both program and function compile, but when I try to link, I get the
message,  "undefined reference to 'read_block_'."

If I use the compile switch -fno-underscoring I similarly get  "undefined
reference to 'read_block'."

I assume this is a name mangling problem, and I need a switch to tell
gFortran to use C type name mangling.
# Is there a solution?
# If it is not yet available in gFortran, is it available in g77?


g77 doesn't have an option AFAIK to produce mixed case link symbols. As your report shows clearly, gfortran follows the Fortran standard in making it default to all lower case. If you want to be compatible with past released versions of gfortran, you must go along with this. Thus the frequent use of C compilations like
gcc -c -DRead_Block=read_block Read_Block.c

Probably by the end of this year, many Fortran compilers will implement the syntax (not tested):

     integer function Read_Block(fnp, fp, fb) bind(c, name='Read_Block')

As you are probably aware, many Fortran compilers for Windows have Windows-specific features for this.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux