[Intel Compiler 8.1] C++ calling Fortran Routine

S

Sascha T.

Hi!

I have desperately searched google and its groups in vain. Hope you can
help with my problem. I need to call some ancient Fortran objects by
C++-main program with the latest Intel Compiler V8.1 on Linux 2.6.x.

Compilers are properly installed and working, means, LD_LIBRARY_PATH and
PATH is set correctly.

Calling Fortan (example.f) from C (main.c) works fine using
icc -c main
ifort -o main main.o function.f -nofor_main

However, C++ seems to have some problems. Here are the codes:

----- FORTRAN: function.f -----

SUBROUTINE fortrantest()
IMPLICIT NONE
PRINT *, "Simple test o.k."
END

----- C++: main.C ----------

#include<iostream>
using namespace std;

extern "C"
{
extern void fortrantest_();
}

int main()
{
cout << "Testing call" << endl;
fortrantest_();
}

----------------------

using
icpc -c main.C
ifort -c function.f -nofor_main

works without errors, but linking with
ifort -o main function.o main.o -nofor_main main.o

produces lots of undefined refs. icpc produces different
and fewer error-messages
icpc -o main function.o main.o
function.o(.text+0x36): In function `fortrantest_':
: undefined reference to `for_write_seq_lis'


Any suggestions welcome!

Thanx

ST
 
S

Shezan Baig

Sascha said:
Hi!

I have desperately searched google and its groups in vain. Hope you can
help with my problem. I need to call some ancient Fortran objects by
C++-main program with the latest Intel Compiler V8.1 on Linux 2.6.x.

Compilers are properly installed and working, means, LD_LIBRARY_PATH and
PATH is set correctly.

Calling Fortan (example.f) from C (main.c) works fine using


However, C++ seems to have some problems. Here are the codes:

----- FORTRAN: function.f -----

SUBROUTINE fortrantest()
IMPLICIT NONE
PRINT *, "Simple test o.k."
END

----- C++: main.C ----------

#include<iostream>
using namespace std;

extern "C"
{
extern void fortrantest_();
}

int main()
{
cout << "Testing call" << endl;
fortrantest_();
}

----------------------

using


works without errors, but linking with


produces lots of undefined refs. icpc produces different
and fewer error-messages

function.o(.text+0x36): In function `fortrantest_':
: undefined reference to `for_write_seq_lis'


Any suggestions welcome!

Thanx

ST

Looks like you're missing some libraries used by your fortran compiler.

-shez-
 
T

Tim Prince

Sascha T. said:
Hi!

I have desperately searched google and its groups in vain. Hope you can
help with my problem. I need to call some ancient Fortran objects by
C++-main program with the latest Intel Compiler V8.1 on Linux 2.6.x.

Compilers are properly installed and working, means, LD_LIBRARY_PATH and
PATH is set correctly.

Calling Fortan (example.f) from C (main.c) works fine using


However, C++ seems to have some problems. Here are the codes:

----- FORTRAN: function.f -----

SUBROUTINE fortrantest()
IMPLICIT NONE
PRINT *, "Simple test o.k."
END

----- C++: main.C ----------

#include<iostream>
using namespace std;

extern "C"
{
extern void fortrantest_();
}

int main()
{
cout << "Testing call" << endl;
fortrantest_();
}

----------------------

using


works without errors, but linking with


produces lots of undefined refs. icpc produces different
and fewer error-messages

function.o(.text+0x36): In function `fortrantest_':
: undefined reference to `for_write_seq_lis'


Any suggestions welcome!
If the compiled objects make calls to a run-time library which came with a
Fortran compiler earlier than ifort 8.0, you will need that library, and you
will not be able to use ifort. You will need also a great deal of luck, and
avoidance of file usage conflicts between your code and the invisible
Fortran. If the objects are actually compatible with ifort, you could link
with ifort, but you need to know the additional libraries involved in icpc
linkage. This will depend on several factors, including whether you are
running 32-bit or one of the 64-bit versions of linux, and whether your icpc
was installed on top of a working g++. For example, I have a project which
requires
ifort *.o -lstdc++ -lunwind -lcxa
on one of those linux versions.
 
S

Sascha T.

OF COURSE! Dump me, thanks for the hint!

I recompiled the .f-object and, using icpc for linking, I added

-L[ifort8.1path]/lib -lifcore

ending up in a successful binary.

Thank you!

Cheers

Am Wed, 16 Feb 2005 14:39:34 +0000 schrieb Tim Prince:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top