- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
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
- Etiquetas:
- Intel® Fortran Compiler
1 Solución
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
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
Enlace copiado
4 Respuestas
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
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
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
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
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
Needless to say, if portable code is acceptable, you should be using the ISO C interoperability implemented in all Fortran compilers of the last few years.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
@Tim
Tanks it works
Tanks it works
Responder
Opciones de temas
- Suscribirse a un feed RSS
- Marcar tema como nuevo
- Marcar tema como leído
- Flotar este Tema para el usuario actual
- Favorito
- Suscribir
- Página de impresión sencilla