Combining C++ and fortran programs
Toon Moene
toon@moene.indiv.nluug.nl
Thu Oct 11 13:14:00 GMT 2001
Friedhelm David wrote:
> I have C++-Programs that I want to call from Fortran.
>
> The name of the function in the C++-Programm cp.C is foo. But when I
> compile the program with " g++ -c cp.C" then the name of the function
> foo in the object modul is foo__FPi. When I compile the Fortan-Program
> with "g77 -c -fno-underscoring fp.f", the name of the called subroutine
> in the Fortran object modul is foo. When I link the programms with
> "g77 fp.o cp.o"I get the error message "undefined reference to `foo'".
The only way that I know of to link C++ functions successfully to
Fortran code is to declare them "extern C { ... }".
Unfortunately, I do not recall the exact syntax for that at present -
but it should be explained in the C++ part of the GCC manual.
Hope this helps,
--
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
Join GNU Fortran 95: http://g95.sourceforge.net/ (under construction)
More information about the Gcc-help
mailing list