开发者

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

All my fortran sources compiled fine with

gfortran -g -c fortran_source.f

and archived in a single library called "mylibrary.a" In there, there exists a function of interest 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 compile my c++ executable, linking the library with

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

No errors or warnings...

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

Note that this program builds and runs correctly 开发者_如何学JAVAon a Linux machine with ifort (linking -lifcore).

Thank you very much!


You need to name your library libMyLibrary.a and put it in your current directory then you can link it using

g++ mainfile.cpp -L. -lMyLibrary

or

g++ mainfile.cpp ./libMyLibrary.a

You can put the library somewhere else. In the first case you'd change the -L. to -L/path/to/the/lib, in the second ./libMyLibrary.a to /path/to/the/lib/libMyLibrary.a

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜