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

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

问题描述

我搜索其他主题,但它们对我没有帮助 =(.在我的工作服务器上,我没有 sudo 权限,所以我安装了 PB

<块引用>

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

然后我使用person"示例创建源文件并成功地使用 protoc 编译它.

我没有 pkg​​-info =(.我尝试用

编译它<块引用>

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

然后有十亿个模拟错误,即

<块引用>

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

我认为是链接问题,但如何解决?

<块引用>

回显 $LD_LIBRARY_PATH/home/用户名/本地/lib

在 main.cpp 中:

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

谢谢.

解决方案

把库放在最后:

<块引用>

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

来自 GCC 链接选项:

<前>-图书馆-l 库链接时搜索名为 library 的库.(第二种选择是将库作为单独的参数仅用于 POSIX 合规性,不推荐使用.)在命令中编写此选项的位置有所不同;链接器搜索和处理库和目标文件它们被指定的顺序.因此,`foo.o -lz bar.o' 在文件 foo.o 之后搜索库 `z' 但是在 bar.o. 之前如果 bar.o 引用 `z' 中的函数,则这些函数可能无法加载.

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

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

Then i create source files with "person" example and succesfully compile it with protoc.

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

and then have a billion simular errors i.e.

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

in main.cpp:

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

Thanks.

解决方案

Put the library at the end:

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

From GCC Link Options:

-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.

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

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

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