- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Tim
Tanks it works
Tanks it works

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page