c++ - Visual Studio (f2c) 中带有静态库的未解析外部

标签 c++ visual-studio-2008 makefile static-libraries f2c

我用过 f2c.exe成功地将一些 Fortran *.f 文件转换为 *.c 文件。我确保 #include "f2c.h" exists在每个 C 文件中,我在 MS VS2008 中添加了包含该头文件的目录:Properties -> C/C++ -> General -> Additional Include Directories

问题始于未解析的外部符号 报告的所有源文件中存在的 f2c IO 和数学函数的错误: 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

我读了here我必须先通过 downloading 生成静态库文件 vcf2c.lib libf2c。所以我使用了nmake in VS2008运行 makefile.vc 并生成 vcf2c.lib,然后我将其复制到我的项目目录中并将其添加到 Configuration Properties -> Linker -> Input -> 附加依赖项,但我仍然得到与以前相同的未解析外部符号。

我是否正确构建了这个库,以便 Visual Studio 能够识别其中的函数?我在这里错过了什么?添加此库似乎具有 效果。感谢您的帮助。

错误示例:

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)

编辑:我一直在尝试诊断库文件本身的任何问题。我什至尝试下载 version that was compiled by someone else ,但仍未解决外部问题。以下是运行 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

虽然我不知道那是什么意思。当我使用/ALL 标志运行它时,我可以在其中看到所需的函数名称,但同样,我不确定如何确定它是否正确。源代码函数和库函数之间是否存在某种不匹配? 16 位与 32 位,C 与 C++ 生成文件选项?

最佳答案

一定是调用约定的问题!只需确保使用相同的调用约定导出函数 (_cdecl 或 _stdcall),或者使用与导出函数相同的调用约定。

关于c++ - Visual Studio (f2c) 中带有静态库的未解析外部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24700505/

相关文章:

java - android jni 从静态方法到非静态方法

c++ - 循环遍历容器作为模板

visual-studio - 注册程序集时出现错误 MSB3216

gcc - Makefile自动链接依赖?

c++ - 当我们重复执行全部命令时会发生什么?

c++ - 如何使用 re2 获取部分匹配项的数量

c++ - 通用回调

c++ - 具有多个项目的 visual studio 解决方案无法编译

c# - 构建流程模板出错

c - Makefile 编译错误未应用 -std=c99