简体   繁体   中英

Unresolved externals with static library in Visual Studio (f2c)

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM