1

I've used f2c.exe successfully in converting some Fortran *.f files into *.c files. I made sure that #include "f2c.h" exists in each C file, and I added the directory containing that header file in MS VS2008: Properties -> C/C++ -> General -> Additional Include Directories

The issue starts with unresolved external symbol errors reported for all the f2c IO and math functions that were present in the source files: s_rsue, e_rsue, s_rsfe, do_uio, f_close, do_fio, do_lio, f_open, s_stop, pow, pow_ri, sqrt, log, exp, tanh, cos, acos, etc.

I read here that I have to generate the static library file vcf2c.lib first by downloading libf2c. So I used nmake in VS2008 to run the makefile.vc and produced vcf2c.lib, which I then copied into my project directory and added it under Configuration Properties -> Linker -> Input -> Additional Dependencies, but I'm STILL getting the same unresolved external symbols as before.

Have I built this library correctly so that Visual Studio will recognize the functions in it? What am I missing here? Adding this library seemed to have zero effect. Thanks for any help.

Examples of errors:

error LNK2019: unresolved external symbol "long __cdecl e_rsue(void)" (?e_rsue@@YAJXZ) referenced in function _main
error LNK2019: unresolved external symbol "long __cdecl do_uio(long *,char *,long)" (?do_uio@@YAJPAJPADJ@Z) referenced in function _main
error LNK2019: unresolved external symbol "long __cdecl s_rsue(struct cilist *)" (?s_rsue@@YAJPAUcilist@@@Z) referenced in function _main
error LNK2019: unresolved external symbol "double __cdecl log(double)" (?log@@YANN@Z) referenced in function _main
error LNK2019: unresolved external symbol "double __cdecl sqrt(double)" (?sqrt@@YANN@Z) referenced in function "int __cdecl calcfl_(void)" (?calcfl_@@YAHXZ)
error LNK2019: unresolved external symbol "double __cdecl cos(double)" (?cos@@YANN@Z) referenced in function "int __cdecl waveno_(float *,float *)" (?waveno_@@YAHPAM0@Z)

EDIT: I've been trying to diagnose any problems within the library file itself. I even tried downloading a version that was compiled by someone else, but still not resolving the externals. Here are the results of running dumpbin:

dumpbin /exports vcf2c.lib

Dump of file vcf2c.lib

File Type: LIBRARY
  Summary
    18A0 .bss
     246 .data
    1110 .debug$F
    513C .debug$S
    1C17 .drectve
     B73 .rdata
    A5BD .text

I don't have any idea what that means though. When I run it with the /ALL flag, I can see the desired function names in there, but again, I'm not sure how to determine if it's proper. Could there be some kind of mismatch between the source code functions and the library's? 16bit vs. 32bit, C vs. C++ makefile options?

1
  • 1
    experiencing the same prob here! But the surprise is, I could compile 64-bit version but not 32-bit version..
    – rampireram
    Nov 10, 2014 at 6:36

1 Answer 1

1

It must be the problem with the calling convention! Just make sure the functions were exported with the same calling convention (_cdecl or _stdcall) or else use the same calling convention as used by the exported functions.

3
  • Since these functions are defined in the library (I think with _cdecl), then it might be possible that my code in VS is trying to call them with _stdcall or _fastcall. How would I instruct the call to use _cdecl?
    – MasterHD
    Nov 12, 2014 at 11:06
  • 1
    @MasterHD It's just the flag used while compiling.(/Gz) for __stdcall. (/Gd) for __cdecl. Refer msdn.microsoft.com/en-us/library/zkwh89ks.aspx
    – rampireram
    Nov 29, 2014 at 10:36
  • It looks like VS was already using (/Gd) __cdecl, and when I tried changing it to __fastcall (/Gr) or __stdcall (/Gz), it gave: "warning C4007: 'main' : must be '__cdecl'". I've already moved on though since I manually converted all f2c functions into native C functions anyway. It was tedious, but looks MUCH cleaner now anyway, so I'll probably delete this question since I'll never know what the actual problem was.
    – MasterHD
    Nov 29, 2014 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.