Hello,
I'm trying ot integrate a Unix domain socket C routine into my Fortran90 program. Therefore I've created a simple test example. I'm using openSUSE 11.1, Intel Fortran Compiler 11.1 and Intel C Compiler 11.1.
The C routine:
// C++ - Routine
#include
#include
extern "C" void pythagoras (float a, float b, float *c)
{
*c = (float) sqrt(a*a+b*b);
}
The Fortran program:
module cproc
interface
subroutine pythagoras (a, b, res )
! DEC$ ATTRIBUTES C :: pythagoras
! DEC$ ATTRIBUTES REFERENCE :: res
real :: a, b, res
end subroutine
end interface
end module
program fmain
use cproc
implicit none
real :: x, y, z
write (* ,*) ' Berechnung der Hypotenusenlaenge eines rechtwickligen Dreiecks '
write (* ,*) ' Geben Sie die beiden Seitenlaengen ein , die den rechten Winkel '
write (* ,*) ' einschliessen :'
read (* ,*) x, y
call pythagoras (x,y,z)
write (* ,*) ' Die Laenge der Hypotenuse betraegt : ', z
end program fmain
The C routine is compiled by:
icc -c crout.cpp
The program then is compiled and linked by:
ifort fmain.f90 crout.o -cxxlib -o prog.out
The error message:
/tmp/ifortMMrDlc.o: In function `MAIN__':
fmain.f90:(.text+0x170): undefined reference to `pythagoras_'
occurs.
Is there is someone who can help me?
Thanks in advance.
jz001
I'm trying ot integrate a Unix domain socket C routine into my Fortran90 program. Therefore I've created a simple test example. I'm using openSUSE 11.1, Intel Fortran Compiler 11.1 and Intel C Compiler 11.1.
The C routine:
// C++ - Routine
#include
#include
extern "C" void pythagoras (float a, float b, float *c)
{
*c = (float) sqrt(a*a+b*b);
}
The Fortran program:
module cproc
interface
subroutine pythagoras (a, b, res )
! DEC$ ATTRIBUTES C :: pythagoras
! DEC$ ATTRIBUTES REFERENCE :: res
real :: a, b, res
end subroutine
end interface
end module
program fmain
use cproc
implicit none
real :: x, y, z
write (* ,*) ' Berechnung der Hypotenusenlaenge eines rechtwickligen Dreiecks '
write (* ,*) ' Geben Sie die beiden Seitenlaengen ein , die den rechten Winkel '
write (* ,*) ' einschliessen :'
read (* ,*) x, y
call pythagoras (x,y,z)
write (* ,*) ' Die Laenge der Hypotenuse betraegt : ', z
end program fmain
The C routine is compiled by:
icc -c crout.cpp
The program then is compiled and linked by:
ifort fmain.f90 crout.o -cxxlib -o prog.out
The error message:
/tmp/ifortMMrDlc.o: In function `MAIN__':
fmain.f90:(.text+0x170): undefined reference to `pythagoras_'
occurs.
Is there is someone who can help me?
Thanks in advance.
jz001
1 解答
Put the .o file before the .f90 file on the ifort command line, and if that doesn't do it, try adding the underscore _ to the end of the C routine name and recompiling.
Tim
Tim
链接已复制
4 回复数
Put the .o file before the .f90 file on the ifort command line, and if that doesn't do it, try adding the underscore _ to the end of the C routine name and recompiling.
Tim
Tim
The Mixed Language Programming chapter of the Intel Fortran Users Guide will help you with this program. You should read about the different possible ways of linking C/C++ with Fortran, and make a selection suited to your needs.
The default calling convention for Fortran is by address, and the default symbol decoration is to append an underscore. One solution is to change the C++ routine to
// C++ - Routine
#include
extern "C" void pythagoras (float *pA, float *pB, float *c)
{float a=*pA, b=*pB;
*c = (float) sqrt(a*a+b*b);
}
and to compile using:
g++ -c pyth.cpp
ifort -assume nounderscoring fmain.f90 pyth.o
The default calling convention for Fortran is by address, and the default symbol decoration is to append an underscore. One solution is to change the C++ routine to
// C++ - Routine
#include
extern "C" void pythagoras (float *pA, float *pB, float *c)
{float a=*pA, b=*pB;
*c = (float) sqrt(a*a+b*b);
}
and to compile using:
g++ -c pyth.cpp
ifort -assume nounderscoring fmain.f90 pyth.o