This is the mail archive of the
mailing list for the Cygwin project.
Re: linking C++ code against library from fortran sources
- From: Danny Smith <danny_r_smith_2001 at yahoo dot co dot nz>
- To: Hans Horn <hannes at 2horns dot com>, cygwin at cygwin dot com
- Date: Sun, 9 Dec 2001 13:25:23 +1100 (EST)
- Subject: Re: linking C++ code against library from fortran sources
--- Hans Horn <firstname.lastname@example.org> wrote: > Hi everybody,
> I have a bunch of old numerical fortran77 sources, which I compiled with
> 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
> 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.
> think I've told the linker properly, where to look for archives (-L<path
> 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
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!
> Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
> Bug reporting: http://cygwin.com/bugs.html
> Documentation: http://cygwin.com/docs.html
> FAQ: http://cygwin.com/faq/
http://shopping.yahoo.com.au - Yahoo! Shopping
- Free CDs for thousands of Priority Shoppers!
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html