VS跨版本编译问题

当使用新版本VS打开旧版本的工程编译时,可能会遇到符号问题

1
2
无法解析的外部符号 __imp___vsnprintf
无法解析的外部符号 __iob_func

无法解析的外部符号 __imp___vsnprintf

在 vs2015 工程选项,链接器附加依赖项里面添加 legacy_stdio_definitions.lib 即可。

出现这个问题的原因是 新版本vs 默认编译时将许多标准库采用内联方式处理,因而没有可以链接的标准库文件,所以要专门添加标准库文件来链接标准库中的函数。

无法解析的外部符号 __iob_func

其实 __iob_func 和 __iob 都是用来定义 stdin,stdout,stderr,只是不同的VC版本实现方式不同。

下面是VS2015的头文件corecrt_wstdio.h中对stdin,stdout,stderr定义

1
2
3
4
5
ACRTIMP_ALT FILE* __cdecl __acrt_iob_func(unsigned);

#define stdin (__acrt_iob_func(0))
#define stdout (__acrt_iob_func(1))
#define stderr (__acrt_iob_func(2))

原来在 VS2015 中 __iob_func 改成了 __acrt_iob_func

在自己的代码中增加了一个名为 __iob_func 转换函数:

1
2
3
4
5
6
7
8
9
10
#if _MSC_VER>=1900
#include "stdio.h"
_ACRTIMP_ALT FILE* __cdecl __acrt_iob_func(unsigned);
#ifdef __cplusplus
extern "C"
#endif
FILE* __cdecl __iob_func(unsigned i) {
return __acrt_iob_func(i);
}
#endif /* _MSC_VER>=1900 */

再次编译,错误消失。


VS跨版本编译问题
https://feater.top/cpp/how-to-fix-high-vs-version-compile-error/
作者
JackeyLea
发布于
2024年4月3日
许可协议