gpt4 book ai didi

c++ - 无法从谷歌 Protocol Buffer 编译示例

转载 作者:IT王子 更新时间:2023-10-29 00:03:25 24 4
gpt4 key购买 nike

我用 grep 查找其他主题,但它们对我没有帮助 =(.在我的工作服务器上,我没有 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): undefined reference to `google::protobuf::internal::kEmptyString'

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

echo $LD_LIBRARY_PATH /home/username/local/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 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.

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

关于c++ - 无法从谷歌 Protocol Buffer 编译示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10404027/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com