Topic: Static Library Linking Problems

Hi,

I have built a static fortran library which I am linking with a Microsoft Visual C++ program. The library compiles OK but when I link it with the C++ program there are a number of unresolved externals such as __gfortran_transfer_character_write and __gfortran_st_write_done. There are no problem resolving my functions in the library.

Are there other libraries that I need to link with the C++ program or is there a way to embed these in the fortran library. I have used the -static flag when building the fortran library but this makes no difference.

This also makes me wonder - Will I need to supply redistributables with my application?

Any help would be appreciated.

Tony

Re: Static Library Linking Problems

Tony,

Building a static library in Simply Fortran does not actually import in all the necessary Fortran runtime library routines to your static library.  You would also need to link against

C:\Program Files (x86)\Simply Fortran 2\mingw-w64\mingw\lib64\libgfortran.a

to get all the necessary runtime library routines into your MS Visual C++ project.  However, it isn't as simple as that.  You'll also need the static GCC library that provides some additional runtime routines.  It will get messy very quickly if it even works at all.

What I would instead suggest is that you build a Fortran dynamic link library and enable the "All Static" option under the Linker tab in the Project Options window.  That option will ensure a DLL is built that incorporates all necessary runtime routines.  You can then link your MS Visual C++ project agains the DLL, and you'll only need a single DLL (the one you just built) to be distributed with your application (as well as any other dependencies that MS Visual C++ might introduce, of course).

Jeff Armstrong
Approximatrix, LLC

Re: Static Library Linking Problems

Jeff,

Thanks very much for the reply, this is very helpful.

Tony