By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,238 Members | 1,746 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,238 IT Pros & Developers. It's quick & easy.

[Intel Compiler 8.1] C++ calling Fortran Routine

P: n/a

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

Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Sascha T. wrote:
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


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

-shez-

Jul 23 '05 #2

P: n/a

"Sascha T." <dj************@spammotel.com> wrote in message
news:pa****************************@spammotel.com. ..

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!

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.
Jul 23 '05 #3

P: n/a


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:
For example, I have a project which
requires
ifort *.o -lstdc++ -lunwind -lcxa
on one of those linux versions.


Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.