vs2017无法解析外部符号__imp__fprintf和__imp____iob_func

使用Quick-Cocos2dx-Community3.4创建了一个lua的cocos工程,用vs2017打开编译的时候libcocos2d项目报错了,出现了__imp__fprintf和__imp____iob_func 的错误,上网查了下,大概是因为vs版本不一致导致的。

以下是原帖内容:

-------------------------------------

使用vs2015编译ffmpeg的一个小项时,出现了__imp__fprintf和__imp____iob_func 的错误,google了一下,有的人 建议下载SDL源码重新编译一下,当然这个方案非常不科学。所以又继续搜,终于有所发现。

这是老外的原话:

In visual studio 2015, stdin, stderr, stdout are defined as follow :

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

But previously, they were defined as:

#define stdin  (&__iob_func()[0])
#define stdout (&__iob_func()[1])
#define stderr (&__iob_func()[2])

So now __iob_func is not defined anymore which leads to a link error when using a .lib file compiled with previous versions of visual studio.

To solve the issue, you can try defining __iob_func() yourself which should return an array containing {*stdin,*stdout,*stderr}.

Regarding the other link errors about stdio functions (in my case it was sprintf()), you can add legacy_stdio_definitions.lib to your linker options.

答题意思就是stdin, stderr, stdout 这几个函数vs2015和以前的定义得不一样,所以报错。

解决方法呢,就是使用{*stdin,*stdout,*stderr}数组自己定义__iob_func()

其实就是下边这样。

extern "C" { FILE __iob_func[3] = { *stdin,*stdout,*stderr }; }

然后__imp__fprintf的解决方法就是在链接器输入lib里加上legacy_stdio_definitions.lib这个LIB

-------------------------------------------------------------------------

我试了在libcocos2d项目的cocos2d.cpp里做如下修改:


#pragma comment(lib, "legacy_stdio_definitions.lib") //此为添加的代码

#include "platform/CCPlatformMacros.h"
#include<stdio.h>  //此为添加的代码


extern "C" { FILE __iob_func[3] = { *stdin,*stdout,*stderr }; }   //此为添加的代码

NS_CC_BEGIN

CC_DLL const char* cocos2dVersion()
{
    return "Quick-Cocos2dx-Community 3.6";
}

NS_CC_END

最后编译通过了。

 

原帖地址:

http://www.letg.top/?p=34

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
问题:__imp___iob_func 这个问题是在低版本升级到高版本的Visual Studio时可能会遇到的一个错误。这个错误是由于在高版本中,__iob_func方法名已经被更新,导致编译器找不到对应的方法而引发的。为了解决这个问题,可以尝试以下两种方法: 方法一: 在代码中添加以下代码段: #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 */ 这段代码的作用是将__iob_func方法重新定义为__acrt_iob_func方法,从而解决了方法名更新导致的错误。中提到的代码段。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [__imp____iob_func和__imp__fprintf](https://blog.csdn.net/zsp312717/article/details/113110301)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [错误 LNK2019,无法解析外部符号__imp____iob_func无法解析外部符号 __imp__fprintf 的解决方法。](https://blog.csdn.net/darkdivel314/article/details/84140051)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值