cocos2dx添加第三方库注意事项

xiashulin 2012-07-10

前一段时间,使用cocos2dx2.0,在使用中文转码的时候,老是加载出问题。

Error1errorLNK2019:unresolvedexternalsymbol_libiconv_closereferencedinfunction"public:int__thiscallHelloWorld::GBKToUTF8(classstd::basic_string<char,structstd::char_traits<char>,classstd::allocator<char>>&,charconst*,charconst*)"(?GBKToUTF8@HelloWorld@@QAEHAAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PBD1@Z)F:\cocos2d\cocos2d2\HelloWorld\proj.win32\HelloWorldScene.objHelloWorld

Error2errorLNK2019:unresolvedexternalsymbol_libiconvreferencedinfunction"public:int__thiscallHelloWorld::GBKToUTF8(classstd::basic_string<char,structstd::char_traits<char>,classstd::allocator<char>>&,charconst*,charconst*)"(?GBKToUTF8@HelloWorld@@QAEHAAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PBD1@Z)F:\cocos2d\cocos2d2\HelloWorld\proj.win32\HelloWorldScene.objHelloWorld

Error3errorLNK2019:unresolvedexternalsymbol_libiconv_openreferencedinfunction"public:int__thiscallHelloWorld::GBKToUTF8(classstd::basic_string<char,structstd::char_traits<char>,classstd::allocator<char>>&,charconst*,charconst*)"(?GBKToUTF8@HelloWorld@@QAEHAAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PBD1@Z)F:\cocos2d\cocos2d2\HelloWorld\proj.win32\HelloWorldScene.objHelloWorld

,原因是在引用第三方库的时候,只写了头文件,#include"platform\third_party\win32\iconv\iconv.h"

只要在头文件附近加入

#pragmacomment(lib,"libiconv.lib")

即:

#if(CC_TARGET_PLATFORM==CC_PLATFORM_WIN32)

#include"platform\third_party\win32\iconv\iconv.h"

#pragmacomment(lib,"libiconv.lib")

#endif

可解决中文问题,下面附带函数:

intHelloWorld::GBKToUTF8(std::string&gbkStr,constchar*toCode,constchar*formCode)

{

iconv_ticonvH;iconvH=iconv_open(formCode,toCode);

if(iconvH==0)

{

return-1;

}

constchar*strChar=gbkStr.c_str();

constchar**pin=&strChar;

size_tstrLength=gbkStr.length();

char*outbuf=(char*)malloc(strLength*4);

char*pBuff=outbuf;

memset(outbuf,0,strLength*4);

size_toutLength=strLength*4;

if(-1==iconv(iconvH,pin,&strLength,&outbuf,&outLength))

{

iconv_close(iconvH);

return-1;

}

gbkStr=pBuff;

iconv_close(iconvH);

return0;

}

//-----------------------------------------------------

std::stringtitle="啊看见电算会计快接啊但是";

#if(CC_TARGET_PLATFORM==CC_PLATFORM_WIN32)

GBKToUTF8(title,"gb2312","utf-8");

#endif

CCLabelTTF*pLabel=CCLabelTTF::create(title.c_str(),"Thonburi",24);

相关推荐

NewActivity / 0评论 2020-05-08