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

Accessing Fortran Module data with C++

kdurgarao
Beginner
829 Views
Hello,
I have a difficulty in Mixed language programming. There are many global variables in a fortran module, which have to be accessed from C++ main program. The compiler is giving no errors with the following simple structure, but, linker gives error - 'undefined reference to the common variable in C++ object code'.

fortran module:

MODULE EXAMP
SAVE

REAL, X(4), Y(4), Z(4)
REAL, PARAMETER :: Pi =3.14159

END MODULE EXAMP

C++:
#include

extern "C" float EXAMP_mp_X[4];
extern "C" float EXAMP_mp_Y[4];
extern "C" float EXAMP_mp_Z[4];
extern "C" float EXAMP_mp_Pi;
using namespace std;
int main()
{
.....
....
}
I am using Linux...g++ and gfortran compiler in the following way
gfortran -c mod.f
g++ -c testc.cpp
g++ -o test mod.o testc.o -llapack

Could anyone please share their experience in handling the similar problem. Thanking you,
0 Kudos
0 Replies
Reply