cocos2dx android protobuf,cocos2dx 交叉编译 iconv库 protobuf库

cocos2dx提供三方的iconv来转化字符问题,交叉编译到android的时候,需要引入iconv的module,下载iconv, https://dl.dropbox.com/u/99895284/iconv.zip 解压到cocos2d根目录 ,编写mk:

proto作为游戏中的传输协议一部分是相当的有用(注意将mk,config.h放在同一目录)。版本2.5.0

52b95342ea79f8bfa4d54e37fca5eb31.png

protobuf库:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := protobuf_static

LOCAL_MODULE_FILENAME := libprotobuf

LOCAL_CPPFLAGS += -fexceptions

LOCAL_CPP_EXTENSION := .cc

LOCAL_SRC_FILES := \

google/protobuf/io/zero_copy_stream_impl_lite.cc \

google/protobuf/io/zero_copy_stream_impl.cc \

google/protobuf/io/zero_copy_stream.cc \

google/protobuf/wire_format_lite.cc \

google/protobuf/wire_format.cc \

google/protobuf/unknown_field_set.cc \

google/protobuf/io/tokenizer.cc \

google/protobuf/text_format.cc \

google/protobuf/stubs/substitute.cc \

google/protobuf/stubs/strutil.cc \

google/protobuf/stubs/structurally_valid.cc \

google/protobuf/stubs/stringprintf.cc \

google/protobuf/service.cc \

google/protobuf/repeated_field.cc \

google/protobuf/reflection_ops.cc \

google/protobuf/io/printer.cc \

google/protobuf/compiler/parser.cc \

google/protobuf/stubs/once.cc \

google/protobuf/message_lite.cc \

google/protobuf/message.cc \

google/protobuf/compiler/importer.cc \

google/protobuf/io/gzip_stream.cc \

google/protobuf/generated_message_util.cc \

google/protobuf/generated_message_reflection.cc \

google/protobuf/extension_set_heavy.cc \

google/protobuf/extension_set.cc \

google/protobuf/dynamic_message.cc \

google/protobuf/descriptor_database.cc \

google/protobuf/descriptor.pb.cc \

google/protobuf/descriptor.cc \

google/protobuf/stubs/common.cc \

google/protobuf/io/coded_stream.cc \

google/protobuf/stubs/atomicops_internals_x86_msvc.cc

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)

include $(BUILD_STATIC_LIBRARY)

iconv库:

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))

android.mk  jni中(windows平台 可以自动扫描提取文件夹以及子目录的c,cpp,cc等文件编译):

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := cocos2dcpp_shared

LOCAL_MODULE_FILENAME := libcocos2dcpp

# 遍历目录及子目录的函数

define walk

$(wildcard $(1)) $(foreach e, $(wildcard $(1)/*), $(call walk, $(e)))

endef

# 遍历Classes目录

ALLFILES = $(call walk, $(LOCAL_PATH)/../../Classes)

FILE_LIST := hellocpp/main.cpp

# 从所有文件中提取出所有%.cpp %.c %.cc文件

FILES_SUFFIX := %.cpp %.c %.cc

FILE_LIST += $(filter ${FILES_SUFFIX}, $(ALLFILES))

LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \

#add iconv from thrid part

LOCAL_WHOLE_STATIC_LIBRARIES := iconv_static

LOCAL_WHOLE_STATIC_LIBRARIES += protobuf_static

LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static

LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static

# 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,libprotobuff)

$(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;

}

注意修改iconv中.h ;.c中函数形参,否则编译不过

const char *from_charset, const char *to_charset, const char *inbuf, size_t inlen, char *outbuf, size_t outlen

由于NDK的变更,针对protobuf的编译config.h存在一定的变化 编译android 和IOS 等平台调整:

/* config.h. Generated from config.h.in by configure. */

/* config.h.in. Generated from configure.ac by autoheader. */

/* the name of */

#define HASH_MAP_CLASS unordered_map

#if _WIN32

/* the location of or */

#define HASH_MAP_H

#else

//IOS

#define HASH_SET_H

#endif

#if _WIN32

/* the namespace of hash_map/hash_set */

#define HASH_NAMESPACE std::tr1

#else

//IOS

#define HASH_NAMESPACE std R[2]

#endif

/* the name of */

#define HASH_SET_CLASS unordered_set

#if _WIN32

/* the location of or */

#define HASH_SET_H

#else

//IOS

#define HASH_SET_H

#endif

/* Define to 1 if you have the header file. */

#define HAVE_DLFCN_H 1

/* Define to 1 if you have the header file. */

#define HAVE_FCNTL_H 1

/* Define to 1 if you have the `ftruncate' function. */

#define HAVE_FTRUNCATE 1

#if _WIN32

/* define if the compiler has hash_map */

#define HAVE_HASH_MAP 1

/* define if the compiler has hash_set */

#define HAVE_HASH_SET 1

#else

/*

* TODO: Figure out how to use stlport unordered_map and set.

* For some reason they don't work when I try to point the

* HASH_MAP_H and HASH_SET_H to the stlport files, I get

* compile timer errors.

*/

/* define if the compiler has hash_map */

#undef HAVE_HASH_MAP

/* define if the compiler has hash_set */

#undef HAVE_HASH_SET

#endif

/* Define to 1 if you have the header file. */

#define HAVE_INTTYPES_H 1

/* Define to 1 if you have the header file. */

#define HAVE_LIMITS_H 1

/* Define to 1 if you have the header file. */

#define HAVE_MEMORY_H 1

/* Define to 1 if you have the `memset' function. */

#define HAVE_MEMSET 1

/* Define to 1 if you have the `mkdir' function. */

#define HAVE_MKDIR 1

/* Define if you have POSIX threads libraries and header files. */

#define HAVE_PTHREAD 1

/* Define to 1 if you have the header file. */

#define HAVE_STDINT_H 1

/* Define to 1 if you have the header file. */

#define HAVE_STDLIB_H 1

/* Define to 1 if you have the `strchr' function. */

#define HAVE_STRCHR 1

/* Define to 1 if you have the `strerror' function. */

#define HAVE_STRERROR 1

/* Define to 1 if you have the header file. */

#define HAVE_STRINGS_H 1

/* Define to 1 if you have the header file. */

#define HAVE_STRING_H 1

/* Define to 1 if you have the `strtol' function. */

#define HAVE_STRTOL 1

/* Define to 1 if you have the header file. */

#define HAVE_SYS_STAT_H 1

/* Define to 1 if you have the header file. */

#define HAVE_SYS_TYPES_H 1

/* Define to 1 if you have the header file. */

#define HAVE_UNISTD_H 1

/* Enable classes using zlib compression. */

#define HAVE_ZLIB 1

/* Define to the sub-directory in which libtool stores uninstalled libraries.

*/

#define LT_OBJDIR ".libs/"

/* Name of package */

#define PACKAGE "protobuf"

/* Define to the address where bug reports for this package should be sent. */

#define PACKAGE_BUGREPORT "protobuf@googlegroups.com"

/* Define to the full name of this package. */

#define PACKAGE_NAME "Protocol Buffers"

/* Define to the full name and version of this package. */

#define PACKAGE_STRING "Protocol Buffers 2.5.0"

/* Define to the one symbol short name of this package. */

#define PACKAGE_TARNAME "protobuf"

/* Define to the home page for this package. */

#define PACKAGE_URL ""

/* Define to the version of this package. */

#define PACKAGE_VERSION "2.5.0"

/* Define to necessary symbol if this constant uses a non-standard name on

your system. */

/* #undef PTHREAD_CREATE_JOINABLE */

/* Define to 1 if you have the ANSI C header files. */

#define STDC_HEADERS 1

/* Enable extensions on AIX 3, Interix. */

#ifndef _ALL_SOURCE

# define _ALL_SOURCE 1

#endif

/* Enable GNU extensions on systems that have them. */

#ifndef _GNU_SOURCE

# define _GNU_SOURCE 1

#endif

/* Enable threading extensions on Solaris. */

#ifndef _POSIX_PTHREAD_SEMANTICS

# define _POSIX_PTHREAD_SEMANTICS 1

#endif

/* Enable extensions on HP NonStop. */

#ifndef _TANDEM_SOURCE

# define _TANDEM_SOURCE 1

#endif

/* Enable general extensions on Solaris. */

#ifndef __EXTENSIONS__

# define __EXTENSIONS__ 1

#endif

/* Version number of package */

#define VERSION "2.5.0"

/* Define to 1 if on MINIX. */

/* #undef _MINIX */

/* Define to 2 if the system does not provide POSIX.1 features except with

this defined. */

/* #undef _POSIX_1_SOURCE */

/* Define to 1 if you need to in order for `stat' and other things to work. */

/* #undef _POSIX_SOURCE */

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值