无法从google协议缓冲区编译示例 [英] Can't compile example from google protocol buffers

查看:162
本文介绍了无法从google协议缓冲区编译示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我grep的其他主题,但他们不帮助我=(。
在我的工作服务器,我没有sudo权限,所以我安装PB

I grep for other topics, but they dont help me =(. On my working server, i have no sudo privilegies, so i install PB with

./ configure --prefix = / home / username / local

./configure --prefix=/home/username/local

我没有pkg-info =(。我尝试用

I have no pkg-info =(. I try to compile it with


g ++ -I / home / username / local / include -L / home / username / local / lib -lprotobuf
-lpthread main.cpp person.pb。 cc

g++ -I /home/username/local/include -L /home/username/local/lib -lprotobuf -lpthread main.cpp person.pb.cc

,然后会出现十亿个错误,例如

and then have a billion simular errors i.e.


person.pb.cc :(。text + 0x4cf):未定义的引用
`google :: protobuf :: internal :: kEmptyString'

person.pb.cc:(.text+0x4cf): undefined reference to `google::protobuf::internal::kEmptyString'

我认为这是一个链接问题,但是如何解决呢?

I think, that it is a problem with linking, but how to solve it?


echo $ LD_LIBRARY_PATH
/ home / username / local / lib

echo $LD_LIBRARY_PATH /home/username/local/lib

在main.cpp中:

in main.cpp:

#include "person.pb.h"
...

b
$ b

感谢。

Thanks.

推荐答案

将库结束:


g ++ -I / home / username / local / include -L / home / username / local / lib main.cpp person.pb.cc -lprotobuf -pthread

g++ -I /home/username/local/include -L /home/username/local/lib main.cpp person.pb.cc -lprotobuf -pthread

GCC链接选项


-llibrary
-l library
    Search the library named library when linking. 
    (The second alternative with the library as a separate argument
    is only for POSIX compliance and is not recommended.)

    It makes a difference where in the command you write this option;
    the linker searches and processes libraries and object files in the
    order they are specified.
    Thus, `foo.o -lz bar.o' searches library `z' after file foo.o but
    before bar.o. If bar.o refers to functions in `z', those functions
    may not be loaded.

此外,使用 -pthread 而不是 -lpthread as -pthread 可为预处理器和链接器设置标志。

Also, use -pthread instead of -lpthread as -pthread may set flags for preprocessor and linker.

这篇关于无法从google协议缓冲区编译示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆