首页 > 代码库 > cocos2dx 交叉编译 编译 iconv库
cocos2dx 交叉编译 编译 iconv库
>
cocos2dx提供三方的iconv来转化字符问题,交叉编译到android的时候,需要引入iconv的module,下载iconv,解压到cocos2d根目录 ,编写mk:
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_ARM_MODE := arm ifeq ($(BUILD_WITH_NEON),1) LOCAL_ARM_NEON := true endif LOCAL_MODULE := iconv LOCAL_CFLAGS += -DHAVE_CONFIG_H -DBUILDING_LIBICONV -DIN_LIBRARY # -DLIBICONV_PLUG LOCAL_C_INCLUDES += $(LOCAL_PATH)/include $(LOCAL_PATH)/libcharset $(LOCAL_PATH)/lib $(LOCAL_PATH)/libcharset/include $(LOCAL_PATH)/srclib LOCAL_SRC_FILES := lib/iconv.c libcharset/lib/localcharset.c lib/relocatable.c LOCAL_STATIC_LIBRARIES += charset include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) include $(call all-makefiles-under,$(LOCAL_PATH))
引入module,贴上我的mk
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := cocos2dcpp_shared LOCAL_MODULE_FILENAME := libcocos2dcpp FILE_LIST := hellocpp/main.cpp FILE_LIST += $(wildcard $(LOCAL_PATH)/../../Classes/*.cpp) LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%) LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static #add iconv from thrid part LOCAL_WHOLE_STATIC_LIBRARIES += iconv # LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static # LOCAL_WHOLE_STATIC_LIBRARIES += cocosbuilder_static # LOCAL_WHOLE_STATIC_LIBRARIES += spine_static # LOCAL_WHOLE_STATIC_LIBRARIES += cocostudio_static # LOCAL_WHOLE_STATIC_LIBRARIES += cocos_network_static # LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static include $(BUILD_SHARED_LIBRARY) $(call import-module,.) $(call import-module,audio/android) $(call import-module,iconv) # $(call import-module,Box2D) # $(call import-module,editor-support/cocosbuilder) # $(call import-module,editor-support/spine) # $(call import-module,editor-support/cocostudio) # $(call import-module,network) # $(call import-module,extensions)
编译成功运行
附上两个iconv的基本用法
//icove int Kit::code_convert( const char *from_charset, const char *to_charset, const char *inbuf, size_t inlen, char *outbuf, size_t outlen ) { iconv_t cd; const char *temp = inbuf; const char **pin = &temp; char **pout = &outbuf; memset( outbuf, 0, outlen ); cd = iconv_open( to_charset, from_charset ); if(cd == 0) return -1; if(iconv( cd, pin, &inlen, pout, &outlen ) == -1) return -1; iconv_close( cd ); return 0; } /*UTF8 To GB2312*/ string Kit:: utf2gb( const char *inbuf ) { size_t inlen = strlen( inbuf ); char * outbuf = new char[inlen * 2 + 2]; string strRet; if(code_convert( "utf-8", "gb2312", inbuf, inlen, outbuf, inlen * 2 + 2 ) == 0) { strRet = outbuf; } delete[] outbuf; return strRet; } string Kit:: gb2utf8( const char *inbuf ) { size_t inlen = strlen( inbuf ); char * outbuf = new char[inlen * 2 + 2]; string strRet; if(code_convert( "gb2312", "utf-8", inbuf, inlen, outbuf, inlen * 2 + 2 ) == 0) { strRet = outbuf; } delete[] outbuf; outbuf = NULL; return strRet; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。