I have been trying to develop a shared object in Fortran and then invoke it from a CPP program.
I started with a simple Hello world example. The fortran code (foo.f90) was:
INTEGER :: index
do index = 1,ctr
write (*,*) "Hello World"
END SUBROUTINE FOO
This was then compiled using the
ifc -fPIC -shared -o foo.so foo.f90
The excerpts from the cpp file (firstdl.cpp) which invoked the DSO are
typedef void (*foo_t)(int);
handle = dlopen ("/home/mohan/code/fortran/foo/foo.so", RTLD_LAZY);
printer = (foo_t) dlsym (handle, "foo_");
/* Call the function. */
Note that dlsym is passed foo_, because of the name decoration done by IFC. This was found out using
nm foo.so | grep goo
The cpp code was compiled using the command
gcc firstdl.cpp -ldl
When a.out was executed, I got the error message
Segmentation fault (core dumped)
The same code worked whe I was not passing any parameters from CPP to Fortran. ie the signature of foo was
I really dont know what the problem might be. Also I am a newbie to Linux and this is the first code I am running using gcc/ifc.