Trying to link my C ++ executable to Fortran library (Cygwin environment)

All my fortran sources are compiled with

gfortran -g -c fortran_source.f

and archived in one library called "mylibrary.a" There exists an interest function called "myfunction"

In my C ++ file, I have:

extern "C" void myfunction_(/* all pointers */);
int main(){
cerr << "Mark 1" << endl;
myfunction_(/* all pointers or address_of my variables */);
cerr << "Mark 2" << endl;
}

I am compiling my C ++ executable by linking the library to

g++ mainfile.cpp -L./ -lmylibrary -lgfortran 

No errors or warnings ...

However, when I run my program, it freezes at the first point where myfunction is called (prints "Mark1" but not "Mark 2") ...

Note that this program builds and works correctly on a Linux machine with ifort (linking -lifcore).

Many thanks!

+3
source share
1 answer

libMyLibrary.a ,

g++ mainfile.cpp -L. -lMyLibrary

g++ mainfile.cpp ./libMyLibrary.a

. -L. -L/path/to/the/lib, ./libMyLibrary.a /path/to/the/lib/libMyLibrary.a

+2

Source: https://habr.com/ru/post/1795133/


All Articles