问题描述
我搜索其他主题,但它们对我没有帮助 =(.在我的工作服务器上,我没有 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
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
and then have a billion simular errors i.e.
I think, that it is a problem with linking, but how to solve it?
in main.cpp:
#include "person.pb.h"
...
Thanks.
Put the library at the end:
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.
这篇关于无法从谷歌协议缓冲区编译示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!