1. 程式人生 > >Windows下protoc-gen-go的使用方法(goprotobuf)

Windows下protoc-gen-go的使用方法(goprotobuf)

goprotobuf是go語言中寫的較好的一個實現, linux下的安裝非常方便, 但是windows需要新增plugin的路徑才能識別

先確認你已經設定好GOPATH, 並安裝好goprotobuf

我的goprotobuf路徑是標準的: $GOPATH/src/code.google.com/p/goprotobuf

編譯並安裝proto工具:

go install code.google.com/p/goprotobuf/proto

go install code.google.com/p/goprotobuf/protoc-gen-go

確認$GOPATH/bin下有protoc-gen-go.exe

編譯proto檔案輸出go檔案:

使用命令列編譯path/to/protoc.exe  --plugin=protoc-gen-go=$GOPATH\bin\protoc-gen-go.exe --go_out . --proto_path .  XXX.proto

這裡順便貼出notepad++使用nppexec外掛的command

"path/to/protoc.exe"  --plugin=protoc-gen-go=path/to/gopath/bin/protoc-gen-go.exe --go_out $(CURRENT_DIRECTORY) --proto_path $(CURRENT_DIRECTORY)  $(FULL_CURRENT_PATH)

P.S.

protoc請自行在protobuf官網下載C++原始碼後編譯