2018/04/01

[c/c++]protobuf-c (7)

protobuf-cの使い方を調べている。

前回、ProtobufCBufferSimpleが何か使えるんじゃなかろうかと思ったのだが、packに使うくらいしかなさそうだ。

https://gist.github.com/hirokuma/c79f5c80cfee9db8cc3c968ac4f46819

置き換えてみたのだが、packするサイズは事前に調べられるので、この使い方だと意味は無いな。

repeatedメンバーで個数が増えるときにappendするのがよさそうだが、realloc()で参照するメンバのアドレスを追加し、malloc()でメンバを追加していく方が素直に見える。


protobuf-cを使っているオープンソースが見つけられていなくて、うまい使い方が分からないのだ。
自分で見つけるしかないのか。


サンプルアプリのメモリ解放漏れが気になるので、valgrindで確かめよう。
・・・WSLだと、freeをわざと外しても"All heap blocks were freed -- no leaks are possible"となって信用できんので、ノーマルなUbuntu環境に立て直そう。


git clone https://github.com/google/protobuf.git
cd protobuf
./autogen
make
sudo make install

cd ..
git clone https://github.com/protobuf-c/protobuf-c.git
cd protobuf-c
./configure

protobufのヘッダがないというエラーになった。。。
しかし、config.logを見ると、-std=c++11 or -std=gnu++11と出ていた。

configure:17261: checking google/protobuf/compiler/command_line_interface.h usability
configure:17261: g++ -c -g -O2  -pthread -I/usr/local/include conftest.cpp >&5
In file included from /usr/include/c++/5/mutex:35:0,
                  from /usr/local/include/google/protobuf/stubs/mutex.h:33,
                  from /usr/local/include/google/protobuf/stubs/common.h:52,
                  from /usr/local/include/google/protobuf/compiler/command_line_interface.h:41,
                  from conftest.cpp:61:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.

では、足してみよう。

./configure CPPFLAGS=-std=c++11
make
...
error: ‘scoped_array’ does not name a type

configureは通ったが、makeでエラーだ。
しかし、WSLでprotobufをビルドしたときにはエラーが出なかったはずだ。

configure:17261: checking google/protobuf/compiler/command_line_interface.h usability
configure:17261: g++ -c -g -O2 -I/home/xxx/prog/clang/protobuf/protobuf-c/../../../cpplang/protobuf/install/include -pthread conftest.cpp >&5
configure:17261: $? = 0
configure:17261: result: yes


何か見落としているのだろうか。。。

1 件のコメント:

コメントありがとうございます。
スパムかもしれない、と私が思ったら、
申し訳ないですが勝手に削除することもあります。

注: コメントを投稿できるのは、このブログのメンバーだけです。