5

I'm trying to link in some legacy Fortran code with a Visual Studio C++ project. I tried using the Windows build of gfortran to build my static library but Visual Studio complains about unresolved external symbols. I guessing this is because mixing mingw and visual studio compilers is a horrible, horrible idea.

I've googled a bit and I see my options are Intel's and Lahey's compilers but both carry a hefty price tag.

Does anyone know of other options, or a different approach I can take?

EDIT IN RESPONSE TO COMMENTS

The error I'm getting is:

Error 7 error LNK2019: unresolved external symbol ___chkstk referenced in function fmm

Searching around led me to this, which just seems like a bad idea.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Mark
  • 106,305
  • 20
  • 172
  • 230
  • Visual C++ can link to other compiler's DLLs, so what exactly are the errors you are getting? Are they functions from runtime libs or `_your_fortran_function` or mangled names? – Pete Kirkham Jan 06 '10 at 17:14
  • I second the suggestion to show us the errors. Fortran compilers typically name-mangle routine names with underscores to avoid conflict with C routines. You may need to override this to combine Fortran and C/C++. A recent related question: http://stackoverflow.com/questions/1985819/gfortran-dll-underscore – M. S. B. Jan 06 '10 at 18:51
  • @Pete and @M.S.B, see edits above, thanks for looking. – Mark Jan 06 '10 at 19:43

1 Answers1

2

You could go the old-school route and use f2c to translate your legacy Fortran to standard K&R C which you should be able to build with the MSFT toolchain.

I have not used f2c in many moons and recall it being a tad picky and a pain to work with. As g77 and later gfortan became so much better, there was less and less need to use it.

That said, for your legacy needs it sounds like a good fit. The Wikipedia entry on f2c also contains a link to the f2c sources at Netlib.

Edit: This may not free you from the run-time requirements though -- your C++ app may need to be linked to the f2c runtime.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • @Dirk, excellent idea. The actually worked without any additional linking, all I needed was the f2c.h. If you don't mind, I'm not going to accept your answer yet, I want to see if any more answers get posted. Thanks! – Mark Jan 06 '10 at 19:58
  • Interesting. As I said, I used it many many moons ago and mostly on Linux where linking with -lf2c was de rigeur. Maybe the frontend got better, more complete or you just got lucky with the MSFT libs. – Dirk Eddelbuettel Jan 06 '10 at 20:42