linux protobuf安装和使用

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文件。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值