I've got a Fortran subroutine that I would like to call from a C++ program. It takes a long list of floating-point arguments and uses the iso_c_binding intrinsic module:
subroutine parasolve ( ...... ) bind (c, name='c_parasolve')
use,intrinsic :: iso_c_binding
implicit none
....
Based on what I've read, I understand that I need to use C++'s "extern" command to define the external function before calling it later. I tried it two ways. The first:
extern "C" void c_parasolve( .... );
returns "expected unqualified-id before string constant" at compile time, whereas the second:
extern void c_parasolve( .... );
compiles just fine but fails to link with "undefined reference to 'c_parasolve( .... )'" and ld returns 1.
I'm compiling with:
g++ -c main.cpp
etc, and
gfortran -ffree-form -std=f2003 -c parasolve.f03
to get them into .o ELFs and then attempting to link with:
g++ main.o otherfiles.o parasolve.o -lgfortran
What is the proper way to call this Fortran function?