Cocos2dx cross-compiled iconv Library

Source: Internet
Author: User
>

Cocos2dx provides third-party iconv for character conversion. When cross-compiling to Android, You need to introduce the iconv module, download iconv, decompress it to the cocos2d root directory, and write MK:


LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_ARM_MODE := armifeq ($(BUILD_WITH_NEON),1)LOCAL_ARM_NEON := trueendifLOCAL_MODULE := iconvLOCAL_CFLAGS +=     -DHAVE_CONFIG_H     -DBUILDING_LIBICONV     -DIN_LIBRARY      #  -DLIBICONV_PLUGLOCAL_C_INCLUDES +=     $(LOCAL_PATH)/include $(LOCAL_PATH)/libcharset $(LOCAL_PATH)/lib     $(LOCAL_PATH)/libcharset/include $(LOCAL_PATH)/srclibLOCAL_SRC_FILES :=     lib/iconv.c libcharset/lib/localcharset.c lib/relocatable.cLOCAL_STATIC_LIBRARIES += charsetinclude $(BUILD_STATIC_LIBRARY)include $(CLEAR_VARS)include $(call all-makefiles-under,$(LOCAL_PATH))



Compile Android. mk in JNI


Introduce the module and paste my mk

LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE := cocos2dcpp_sharedLOCAL_MODULE_FILENAME := libcocos2dcppFILE_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_staticLOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static#add iconv from thrid partLOCAL_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_staticinclude $(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)



Compiled successfully

Attach two iconv basic usage

//icoveint 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;}







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.