linux protobuf安装和使用,protobuf和protoc-gen-lua的下载地址:
protobuf的安装:
解压后
/configure && make && sudo make install
安装后路径位于:/usr/local/bin/protoc
protoc-gen-lua的安装:
解压后,cd protoc-gen-lua-master/protobuf
make
make之后报错,报错如下:
gcc -O3 -shared -fPIC pb.c `/usr/bin/pkg-config --cflags lua5.1` -std=gnu99 `/usr/bin/pkg-config --libs lua5.1` -o pb.so
Package lua5.1 was not found in the pkg-config search path.
Perhaps you should add the directory containing `lua5.1.pc'
to the PKG_CONFIG_PATH environment variable
No package 'lua5.1' found
Package lua5.1 was not found in the pkg-config search path.
Perhaps you should add the directory containing `lua5.1.pc'
to the PKG_CONFIG_PATH environment variable
No package 'lua5.1' found
pb.c:440:30: error: array type has incomplete element type
static const struct luaL_reg _pb [] = {
^
pb.c:456:30: error: array type has incomplete element type
static const struct luaL_reg _c_iostring_m [] = {
^
pb.c: In function ‘luaopen_pb’:
pb.c:470:5: warning: implicit declaration of function ‘luaL_register’ [-Wimplicit-function-declaration]
luaL_register(L, NULL, _c_iostring_m);
^
make: *** [pb.so] Error 1
从错误来看,找不到lua5.1.pc,需要设置PKG_CONFIG_PATH这个环境变量,经过搜索发现,实际是需要lua.pc这个问题,需要建立一个软连接,lua5.1.pc指向lua.pc。lua.pc一般位于/usr/lib64/pkgconfig/lua.pc这个目录。PKG_CONFIG_PATH这个环境变量配置成lua5.1.pc这个文件存在的目录。
解决这个问题之后,继续make出现另外一个错误,如下:
gcc -O3 -shared -fPIC pb.c `pkg-config -I/usr/include --cflags lua5.1` -std=gnu99 `pkg-config --libs lua5.1` -o pb.so
-I/usr/include: unknown option
pb.c:440:30: error: array type has incomplete element type
static const struct luaL_reg _pb [] = {
^
pb.c:456:30: error: array type has incomplete element type
static const struct luaL_reg _c_iostring_m [] = {
^
pb.c: In function ‘luaopen_pb’:
pb.c:470:5: warning: implicit declaration of function ‘luaL_register’ [-Wimplicit-function-declaration]
luaL_register(L, NULL, _c_iostring_m);
^
make: *** [pb.so] Error 1
经搜索发现,在pb.c文件中需要增加一个宏定义:#define luaL_reg luaL_Reg。这样就能成功编译出pbc.so文件。接下去就可以使用pbc.so文件。