0

I'm trying to build a project that is mostly C but has some Fortran subroutines. The code is old and I'm trying to make it work on modern machines. My main function calls an external function

extern void __stdcall mainlhs(void);

The function is a subroutine written in Fortan

subroutine mainlhs

I want to convert the Fortran code (which contains this and other subroutines) using f2c and put the result in my project.

f2c does convert the code and the resulting C code does compile. When I try to build the project there are several linking errors.

Error   35  error LNK2019: unresolved external symbol _e_wsle referenced in function _mainlhs_  C:\Users\giazlas\Documents\Socrates Support\projects\lhsforc\lhsforc\UNCER.obj
Error   36  error LNK2019: unresolved external symbol _s_wsle referenced in function _mainlhs_  C:\Users\giazlas\Documents\Socrates Support\projects\lhsforc\lhsforc\UNCER.obj
Error   37  error LNK2019: unresolved external symbol _f_clos referenced in function _mainlhs_  C:\Users\giazlas\Documents\Socrates Support\projects\lhsforc\lhsforc\UNCER.obj
Error   38  error LNK2019: unresolved external symbol _e_rsle referenced in function _mainlhs_  C:\Users\giazlas\Documents\Socrates Support\projects\lhsforc\lhsforc\UNCER.obj
Error   39  error LNK2019: unresolved external symbol _do_lio referenced in function _mainlhs_  C:\Users\giazlas\Documents\Socrates Support\projects\lhsforc\lhsforc\UNCER.obj
Error   40  error LNK2019: unresolved external symbol _s_rsle referenced in function _mainlhs_  C:\Users\giazlas\Documents\Socrates Support\projects\lhsforc\lhsforc\UNCER.obj
Error   41  error LNK2019: unresolved external symbol _f_open referenced in function _mainlhs_  C:\Users\giazlas\Documents\Socrates Support\projects\lhsforc\lhsforc\UNCER.obj
Error   42  error LNK2019: unresolved external symbol _s_stop referenced in function _chlsky_   C:\Users\giazlas\Documents\Socrates Support\projects\lhsforc\lhsforc\UNCER.obj
Error   43  error LNK2019: unresolved external symbol _e_wsfe referenced in function _gaminv_   C:\Users\giazlas\Documents\Socrates Support\projects\lhsforc\lhsforc\UNCER.obj
Error   44  error LNK2019: unresolved external symbol _do_fio referenced in function _gaminv_   C:\Users\giazlas\Documents\Socrates Support\projects\lhsforc\lhsforc\UNCER.obj
Error   45  error LNK2019: unresolved external symbol _s_wsfe referenced in function _gaminv_   C:\Users\giazlas\Documents\Socrates Support\projects\lhsforc\lhsforc\UNCER.obj
Error   46  error LNK2019: unresolved external symbol _pow_dd referenced in function _gamcdf_   C:\Users\giazlas\Documents\Socrates Support\projects\lhsforc\lhsforc\UNCER.obj
Error   47  error LNK2019: unresolved external symbol _pow_ri referenced in function _moment_   C:\Users\giazlas\Documents\Socrates Support\projects\lhsforc\lhsforc\UNCER.obj
Error   48  error LNK2019: unresolved external symbol _s_paus referenced in function _betpdf_   C:\Users\giazlas\Documents\Socrates Support\projects\lhsforc\lhsforc\UNCER.obj

these functions don't appear on the original Fortran code nor anywhere else. I only found references of them on netlib's source of f2c

Thanks for your help

jzlas
  • 187
  • 2
  • 11

1 Answers1

2

I think you also need to link the functions in libf2c, which is avaiable from Netlib, as described at http://www.netlib.org/f2c/README .

Fortranner
  • 2,525
  • 2
  • 22
  • 25
  • Thanks, that worked. But now one of the files in libf2c produces a linking error and I can find the function anywhere on libf2c. s_paus.c calls a function called pause() and this function can't be found anywhere. Error 85 error LNK2019: unresolved external symbol _pause referenced in function _s_paus C:\Users\giazlas\Documents\Socrates Support\projects\lhsforc\lhsforc\s_paus.obj – jzlas May 14 '14 at 22:22
  • Find the calls to pause and see if you can remove them. Often that is the case. – Vladimir F Героям слава May 15 '14 at 08:14
  • I used `nmake` in VS2008 to run the `makefile.vc` from the `libf2c` to generate `vcf2c.lib`. I copied that file into my project directory, then added it under `Configuration Properties/Linker/Input/Additional Dependencies`, but I'm still getting unresolved external symbols for ALL of the IO and math functions being called in my code: `s_rsue, e_rsue, do_uio, f_close, do_lio, f_open, pow, sqrt, log, exp, cos`, etc. What have I done wrong? – MasterHD Jul 11 '14 at 14:25