共2步:
- 下載protobuf代碼並安裝protobuf python
- 下載protoc-gen-lua並安裝
關鍵詞
protobuf
lua
mac
Protocol buffers are a flexible, efficient, automated mechanism for serializing structured data – think XML, but smaller, faster, and simpler. —— [ Google Protobuf ]
下載protobuf代碼並安裝protobuf python
首先從https://github.com/google/protobuf下載最新的protobuf(請注意自己需要使用的protobuf版本,由於protobuf可以跨語言使用,所以版本一致很重要),然後在Terminal中進入下載目錄裏的python目錄下,運行python setup.py(如果有權限問題請在命令前加sudo;由於mac os 10.10自帶python 2.7,所以省去了安裝python的步驟)。
下載protoc-gen-lua並安裝
請到https://github.com/sean-lin/protoc-gen-lua下載最新的protoc-gen-lua,然後在Terminal中進入下載目錄下的protobuf目錄,運行make。
此時可能遇到找不到pkg-config,請在Terminal中運行下列命令
curl http://pkgconfig.freedesktop.org/releases/pkg-config-0.28.tar.gz -o pkg-config-0.28.tar.gz
tar -xf pkg-config-0.28.tar.gz
cd pkg-config-0.28
./configure --with-internal-glib
sudo make install
之後再在protobuf目錄下運行make。如果遇到無法找到lua.h文件,請到https://code.google.com/p/rudix/downloads/detail?name=lua-5.1.4-7.pkg&can=1&q=lua下載此lua並安裝。如果再運行make後遇到無法找到endian.h問題,請在Terminal中運行xcode-select –install,並修改protobuf目錄下的pb.c中的代碼
#ifdef _ALLBSD_SOURCE
#include <machine/endian.h>
#else
#include <endian.h>
#endif
爲
#include <machine/endian.h>
之後make應生成pb.so文件。
然後進入/usr/local/bin目錄運行sudo ln -s /path/to/protoc-gen-lua/plugin/protoc-gen-lua,之後就可以使用protoc命令生成lua文件了
protoc --lua_out=./ foo.proto