Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Linking Fortran and C++ code

velvia
Beginner
391 Views
Hello,
I want to call a C++ code from a Fortran code. I ended up with some problems at link time. To test a few things, I've done some very simple programs and did the following :
icc -c simple-c++.c
ifort -c gFASTdemo-fortran.f90
ifort gFASTdemo-fortran.o simple-c++.o -o main
wheresimple-c++.c is valid for both c and c++. It worked nicely. Then, I did
cpsimple-c++.csimple-c++.cpp
icc -c simple-c++.cpp
ifort -c gFASTdemo-fortran.f90
ifort gFASTdemo-fortran.o simple-c++.o -o main
and I now have the following output :
gFASTdemo-fortran.o: In function `MAIN__':
gFASTdemo-fortran.f90:(.text+0x3d9): undefined reference to `gFastVis'
simple-c++.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
I understand that Fortran is interoperable with C and not with C++. But, is there a workaround to make it work with C++ ?
Francois
0 Kudos
2 Replies
mecej4
Honored Contributor III
391 Views
You can call from Fortran a routine within a C++ source file if the routine is declared to have C linkage. For example:

extern "C" {...};

0 Kudos
TimP
Honored Contributor III
391 Views
You will also require -lstdc++ appended to your link command.
0 Kudos
Reply