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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章