compilation - Calling Fortran subroutine from C++, undefined reference when linking -


i've got fortran subroutine call c++ program. takes long list of floating-point arguments , uses iso_c_binding intrinsic module:

subroutine parasolve ( ...... ) bind (c, name='c_parasolve')   use,intrinsic :: iso_c_binding   implicit none .... 

based on i've read, understand need use c++'s "extern" command define external function before calling later. tried 2 ways. first:

extern "c" void c_parasolve( .... ); 

returns "expected unqualified-id before string constant" @ compile time, whereas second:

extern void c_parasolve( .... ); 

compiles fine fails link "undefined reference 'c_parasolve( .... )'" , ld returns 1.

i'm compiling with:

g++ -c main.cpp 

etc, and

gfortran -ffree-form -std=f2003 -c parasolve.f03 

to them .o elfs , attempting link with:

g++ main.o otherfiles.o parasolve.o -lgfortran 

what proper way call fortran function?

it looks extern "c" declaration inside function or class definition. not allowed -- has @ top level in source file. (yes, error message more informative!)


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -