This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: linking C++ code against library from fortran sources

 --- Hans Horn <> wrote: > Hi everybody,
> I have a bunch of old numerical fortran77 sources, which I compiled with
> g77
> and archived into, say libMyF77.a.
> I want those f77 functions to be called from w/i a c++ program.
> Here are my two questions:
> 1. to satisfy the compiler, I have to declare the functions used as
> 'extern'. Which language string should I be using?
> "FORTRAN" as language string (as I had used on other platforms, such as
> AIX)
> is not recognized by gcc/g++
>  gcc/g++ accepts only either "C" or nothing (or ????). Which is the right
> one here?

As you say, extern "FORTRAN" doesn't work.  It should be extern "C".  Note
that g77 uses C calling convention (__cdecl) by default for Fortran. Other
compilers use PASCAL (__stdcall)

2. the linker complains about the functions used as undefined references.
> I
> think I've told the linker properly, where to look for archives (-L<path
> to
> libMyF77.a> -lMyF77). What am I doing wrong? Do I have to do something
> special when archiving? Do I have to raise another magic flag for the
> linker????

By default, g77 appends an underscore to Fortan names, so you will need to
do same in your C/C++ code.  If you can rebuild the libs, you may add
-fno-underscore option to override this decoration. 

Have a look at either the netlib Lapack++ package (C++ wrappers for Fortran
blas and lapack) or Roldan Pozo's TNT package (a start a templated version
of Lapack++) here:


> Any light shed onto the subject is severely appreciated!
> Hans
> --
> Unsubscribe info:
> Bug reporting:
> Documentation:
> FAQ:         
> - Yahoo! Shopping
- Free CDs for thousands of Priority Shoppers!

Unsubscribe info:
Bug reporting:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]