在cocos2dx中应用protobuf

Cocos2d-x中配置Protobuf(win32和android) 今天讲一下在cocos2d-x-3.17.2项目中配置protobuf-3.12.0-rc2。 1.下载cocos2d-x-3.17.2:https://www.cocos.com/cocos2dx解压到:c:/cocos2d-x-3.17.2 2.下载protobuf-3.12.0-rc2:https://github.com/protocolbuffers/protobuf/releases/,解压到:c:/protobuf-3.12.0-rc2 要使cocos2d-x-3.17.2能编译An.. 阅读详情

protobuf在各个平台下编译好痛苦!!!  各种失败!! 经过两天的努力终于成功了!!!所以有必要记录下,以方便会他人会用到(网上查阅了很多资料, 很是感激那些作者)

去https://code.google.com/p/protobuf/downloads/list下载版本protobuf-2.5.0.tar.bz2, 然后解压 如图


为了解决ios平台下可能的名字空间冲突,  切换到src/google/protobuf下,运行下面的命令

sed -i '' -e 's/namespace\ google /namespace\ google_public /g' $(find . -name \*.h -type f)
sed -i '' -e 's/namespace\ google /namespace\ google_public /g' $(find . -name \*.cc -type f)
sed -i '' -e 's/namespace\ google /namespace\ google_public /g' $(find . -name \*.proto -type f)
sed -i '' -e 's/google::protobuf/google_public::protobuf/g' $(find . -name \*.h -type f)
sed -i '' -e 's/google::protobuf/google_public::protobuf/g' $(find . -name \*.cc -type f)
sed -i '' -e 's/google::protobuf/google_public::protobuf/g' $(find . -name \*.proto -type f)


新建一个cocos2dx工程以后测试用。

在cocos2dx工程的Classes目录中新建目录pb, protobuf_base。 pb用来放proto转换后的.cc和.h文件; protobuf_base目录下放置protobuf必须的头文件及各平台下的库文件。按如下截图建立各个目录



下面一步步来编译各个环境

1. Windows下 直接打开vsprojects下的protobuf工程文件, 有些vs版本可能会提示对项目方案的一些更改,点击确定。

    然后右键protobuf, 生成, 之间可能会有些错误, 不用管,是一些google的测试文件,无视之!

在debug目录下会生成4个重要的文件protoc.exe,libprotobuf.lib, libprotobuf-lite.lib,libprotoc.lib

其中protoc.exe是用来生成.h和.cc文件的。  将这4个文件拷贝到Classes/protobuf_base/lib/win32下。

2.Android下的编译

   将下载好的protobuf源码拷贝一份到cocos2dx工程的Classes目录中, 重新命名为protobufxx(临时编译Android用, 编译好后将会删除)

   在src目录中新建头文件config.h, 内容如下:

   

#define HASH_SET_H <ext/hash_set>
#define HASH_MAP_H <ext/hash_map>
#define HASH_NAMESPACE __gnu_cxx

 
#define HAVE_PTHREAD

   打开刚才新建的cocos2dx工程下中Android项目下的编译文件Android.mk, 修改为如下

LOCAL_PATH := $(call my-dir)
 
include $(CLEAR_VARS)
 
LOCAL_MODULE := protobuf

LOCAL_SRC_FILES := ../../classes/protobufxx/src/google/protobuf/descriptor.cc \
                   ../../classes/protobufxx/src/google/protobuf/descriptor.pb.cc \
                   ../../classes/protobufxx/src/google/protobuf/descriptor_database.cc \
                   ../../classes/protobufxx/src/google/protobuf/dynamic_message.cc \
                   ../../classes/protobufxx/src/google/protobuf/extension_set.cc \
                   ../../classes/protobufxx/src/google/protobuf/extension_set_heavy.cc \
                   ../../classes/protobufxx/src/google/protobuf/generated_message_reflection.cc \
                   ../../classes/protobufxx/src/google/protobuf/generated_message_util.cc \
                   ../../classes/protobufxx/src/google/protobuf/message.cc \
                   ../../classes/protobufxx/src/google/protobuf/message_lite.cc \
                   ../../classes/protobufxx/src/google/protobuf/reflection_ops.cc \
                   ../../classes/protobufxx/src/google/protobuf/repeated_field.cc \
                   ../../classes/protobufxx/src/google/protobuf/service.cc \
                   ../../classes/protobufxx/src/google/protobuf/text_format.cc \
                   ../../classes/protobufxx/src/google/protobuf/unknown_field_set.cc \
                   ../../classes/protobufxx/src/google/protobuf/wire_format.cc \
                   ../../classes/protobufxx/src/google/protobuf/wire_format_lite.cc \
                   ../../classes/protobufxx/src/google/protobuf/io/coded_stream.cc \
                   ../../classes/protobufxx/src/google/protobuf/io/gzip_stream.cc \
                   ../../classes/protobufxx/src/google/protobuf/io/printer.cc \
                   ../../classes/protobufxx/src/google/protobuf/io/tokenizer.cc \
                   ../../classes/protobufxx/src/google/protobuf/io/zero_copy_stream.cc \
                   ../../classes/protobufxx/src/google/protobuf/io/zero_copy_stream_impl.cc \
                   ../../classes/protobufxx/src/google/protobuf/io/zero_copy_stream_impl_lite.cc \
                   ../../classes/protobufxx/src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc \
                   ../../classes/protobufxx/src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc \
                   ../../classes/protobufxx/src/google/protobuf/stubs/common.cc \
                   ../../classes/protobufxx/src/google/protobuf/stubs/once.cc \
                   ../../classes/protobufxx/src/google/protobuf/stubs/stringprintf.cc \
                   ../../classes/protobufxx/src/google/protobuf/stubs/structurally_valid.cc \
                   ../../classes/protobufxx/src/google/protobuf/stubs/strutil.cc \
                   ../../classes/protobufxx/src/google/protobuf/stubs/substitute.cc \         

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../Classes/protobufxx/src
                   
 
include $(BUILD_STATIC_LIBRARY)
编译后去obj目录下把libprotobuf.a拷贝到Classes/protobuf_base/lib/android下

 3.IOS下的编译

参考https://gist.github.com/strahlex/10585771

将生成的libprotobuf.a,libprotobuf-lite.a 拷贝到Classes/protobuf_base/lib/ios下



可以去http://download.csdn.net/detail/jijun7885417/7403681  下载

cocos2dx lua + protobuf vs 2015 cocos2dx 3.10  lua  protobuf1. 下载 protobuf 源码     https://github.com/bnnswyp/protobuf/tree/master/protobuf-2.5.0    解压后的文件列表如下所示         其中 vsprojects 文件夹为 protobuf 的vs 工程2. 打开 protobuf.sln 编译... 阅读详情

相关推荐

cocos2dx 面试者(入门到高级) 必备知识

请关注订阅,本专栏会详细讲解cocos2dx开发各个重要的模块,实现中大型游戏开发 文本以cocos2d 3.17.2版本为例,本篇内容专门为从事cocos2d开发的面试者提供帮助,精准解决面试遇到的问题,欢迎讨论 一、 引擎部分 1.cocos2d采用什么内存管理机制(引用计数)以及如何实现的 答:采用引用计数管理内存,所有引擎对象的基类Ref中定义了一个成员变量_referenceCount 并在构造函数中初始化为1(这句很重要) 2.cocos2dx 基本的类有哪些,并说明引擎如何运行的 答: .

刀客 1699

cocos2dx-c++接入 protobuf3.x

1,找到libsimulator 工程 FileServer.cpp 文件 注释 addResponse里面所有内容 注释 loopResponse里面所有内容 注释 loopWriteFile 注释 loopReceiveFile FileServer.h //#include “Protos.pb.h” RecvBufStruct 内容置空 ResponseStruct 内容置空 删除 protobuf-lite 文件夹 2,然后CMakeLists.txt 去除所有关于的google的路径文件(an

qq_33039615的博客 352

cocos2dx-network:使用Google protobuf的Skynet的cocos2dx客户端示例

使用Google protobuf的Skynet的cocos2dx客户端示例

ios 平台 cocos2d-x 集成 protobuf

一、参考资料: protobuf之为cocos2dx编译ios下的静态库 Android与ios引入protobuf ---for cocos2dx 二、失败症结: 1.从 google code上面无法下载到直接可用的库成品(.a + .h 或 .dylib + .h),也没有提供干净清新可以直接拿来用的代码。 能下载到的只会是同一份过分完整源码的三种不同格式的压缩包。

客亦知夫水与月乎? 1万+

Cocos2dx 集成 protobuf2.5 工程(XCode)

使用说明: 1.将 libs 目录下的 protobuf 移动到自己工程的 libs 目录下 2.在 Target 的 Header Search Paths 中添加: "$(PROJECT_NAME)/libs/protobuf/src" 3.测试是否可用: 首先编写 .proto 文件,用 protoc 生成 cpp 的头文件和实现文件 然后再可执行的代码文件中包含生成的头文件,编译,如果不出错则表示已经集成成功。 重新造轮子?没问题: http://blog.csdn.net/yang3wei/article/details/9369735

cocos2d-x3.2与Firefly服务端信息交互(protobuf版本)

更深入的cocos2dx与firefly通信代码,包含网络收发消息的完整示例,解析数据使用的是protobuf

cocos2dx中protobuf的lua使用

一、protobuf常规使用。 1 环境:win7-64机, 安装好python2.7,vs2013,cocos2dx-3.1.1,protobuf-2.6.1 2 准备:protobuf  下载地址:官方 https://github.com/google/protobuf     我的:http://download.csdn.net/detail/c471961491/9279185

不加香精的专栏 4056

cocos2dx集成protobuf android版

protoc.exe能同时生成简化的类,便于游戏内业务逻辑使用,不要使用message嵌套和group,记得加上package,否则名字冲突

cocos2dx 3.x 集成protobuf

vs2013+cocos2dx 3.13.1这篇博文是集成Lua版本的protobuf,集成C++版本的过程也可参考。主要参考博文地址《cocos2dx 3.x C++搭建protobuf环境》,这里的集成方式和参考博文有点不一样(这里是直接集成到引擎中,参考博文是当成一个库放到项目中),请仔细甄别。 1.下载pbc①下载地址 pbc:https://github.com/cloudwu/pbc②...

aizhiqiang2的博客 928

XCode-cocos2dx-集成protobuf的demo工程

XCode-cocos2dx-集成protobuf的demo工程. 详见 http://blog.csdn.net/yang3wei/article/details/9369735

别再为采样窗口发愁了!手把手教你用STM32实现三电阻分扇区电流采样(附代码避坑)

本文详细介绍了STM32平台下三电阻分扇区电流采样的实现方法,重点解决采样窗口选择不当和扇区切换逻辑问题。通过PWM定时器与ADC协同工作的底层机制分析,提供可移植的代码示例和实战经验,帮助工程师在电机矢量控制(FOC)系统中实现高精度相电流采样。

weixin_42531516的博客 172

cocos2dx使用lua和protobuf

为了使游戏开发更加方便快捷,我继续了protobuf在lua下的尝试。 socket使用的是cocos2dx集成的websocket。 先说下环境:cocos2d-x-2.2.1 + protobuf 2.5.0 +protoc-gen-lua +Python 2.7.5 1.在protobuf目录下依次执行如下命令 python setup.py build python set...

modabobo 73

CAN:CANape使用Function处理数据

CANape中的function and script习惯称之为脚本(实际为函数和脚本)。这里介绍function,可以实现简单信号a和信号b乘法,比如计算功率(转速与扭矩乘)。该功能前期有专业人员做支援,当时问其编制方法,其回答是看帮助文件。现在没有支援自己动手。 功能描述:电压信号阶梯增加,每次保持1.5s,测量后0.5s位移平均值(假设信号步长10ms,需要取样50个点,但该脚本中点的数目为10个)。图示如下: 刚开始看了软件Function definition→Library function,

Morven 1万+

cocos2d-x protobuf; cocos2dx protocol buffer

昨天了解到项目要用到protocol buffer,今天晚上看了一下,了解protobuf本质上就是一个信息表达协议+编辑,解析库。 linux开源软件都一个模式,先./configure --help &gt; build.sh 看看有那些东西,再configure make 。。。  根据官网文档弄个简单write,read 的test大致了解一下是啥情况。 ok,到这里我们...

weixin_34021089的博客 142

树莓派5首次开机保姆级教程(无显示器通过VNC连接树莓派桌面)

选择 Interface Options > VNC > Yes 启用服务。2.在Windows电脑上安装VNC软件。重启树莓派:sudo reboot。3.使用VNC远程访问树莓派桌面。

qq_34184505的博客 2361

Unity面试题总结

Unity面试题

sinat_34014668的博客 1万+

cocos2dx-c++接入protobuf(xcode ios)

压根没有写博文的习惯,但是这次项目因为protobuf耽误了很多时间,而且baidu和Google上我也找了很多方法,走了很多弯路,但终究还是弄好了,为了庆祝下,就分享下配置过程吧。 1.我的配置环境: 系统:macOS Mojave10.14.16; Xcode:v10.3; protobuf:v2.5....

qq_31773413的博客 958

《SAP FICO系统配置从入门到精通共40篇》030、集成配置:FI与生产计划(PP)的自动科目确定

FI和PP的自动科目确定,本质上是把生产业务翻译成会计语言。翻译规则就藏在那些配置表里。配的时候多想一步:这个业务动作,在财务眼里是什么?是材料消耗?是产出入库?还是工费分摊?想清楚这个,再看配置界面,那些代码就不是天书了。最好的测试方式,是月底关账前,让生产部门跑一遍所有类型的生产订单。配置对不对,业务最知道。

985大学毕业,前某大厂员工,啥都会点的程序员! 579

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 protobuf库:LOC...

weixin_28819153的博客 311

【C语言笔记初级篇】第一章:C语言快速入门及注意事项

(1)第一个C语言程序 A:利用vs2010写C语言程序 1:按以下步骤新建工程 2:添加源文件,“.c”文件 B:第一个C语言代码 1:以下是基本的C语言程序 2:由于没有设置连接器,所以打印结果没有显示,按照如下步骤链接控制台 (2)数据类型 A:基本数据类型及占用字节 B:一些概念的梳理 概念一:关于计算机的单位 位(bit):计算机通过电路的开关和闭合处理信息,电路通...

快乐江湖的博客 3752

Windows Docker Desktop部署MaxKB详细教程

MaxKB(Max Knowledge Base)是一款基于大语言模型(LLM)和检索增强生成(RAG)技术的开源知识库问答系统,旨在帮助企业、教育机构及研究组织高效管理知识并提供智能问答服务。

猿小白的博客 1385
上一篇: 对c++ 标准库中算法传递参数
下一篇: 给cocos2dx的ui::ScrollView增加滚动条
旺旺队力功
博客等级 码龄17年 17粉丝 32原创
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值