xcode在os x下编译使用protobuf
os x系统下xcode中使用protobuf
最近在用cocos2dx做小游戏,希望用到网络部分,所以希望protobuf能在mac平台上工作,baidu和goole了一下后发现大部分都是重复的一两篇技术文章,转来转去,而且按照这两篇文章搞了一下都没有成功,后来发现了两篇实用的文章后才解决了问题,记录一下:
主要参考两篇在网上流传不广的文章.http://blog.csdn.net/deep_coder/article/details/38055275
http://blog.csdn.net/rct1985/article/details/9340641
在 https://code.google.com/p/protobuf/downloads/list
这里下载最新的SourceCode工程, 我用的是2.5.0版本,下载完解压下指定目录下。
cd yourDir
./configure
make
make check
sudo make install
安装成功后在需要用到protobuf的xcode工程里:
a. 把解压完的目录下 protobuf-2.5.0/src/google整个目录拷贝到cocos2d-x工程下的libs目录下。
b. 把解压完的目录下 config.h 拷贝到 libs/google 目录下,主要是放到一些宏定义, 没办法,代码被引用了。
c. 删除编译多语言相关文件,google/protobuf/compiler 目录是用来编译多语言的,删除
d. 删除单元测试文件 所有 *unittest.cc 文件是测试用例(根据文件名猜的),删除, 还有两个tesst打着的文件夹
然后编译,会出现这个错误”#error Host architecture was not detected as supported by protobuf”
解决这个问题的方法是:
In platform_macros.h, Replace
#else
#error Host architecture was not detected as supported by protobuf
#endif
By:
#elif defined(__aarch64__)
#define GOOGLE_PROTOBUF_ARCH_ARM 1
#define GOOGLE_PROTOBUF_ARCH_64_BIT 1
#else
#error Host architecture was not detected as supported by protobuf
#endif
最后再编译就OK了!