[英]C++ Linux Google Protocol Buffers - cannot run compiled proto cpp files from tutorial
I'm following the cpp tutorial on google protocol buffers 我正在关注Google协议缓冲区的cpp教程
I installed Google Protocol Buffers on Ubuntu and compiled the .proto file so I got the pb.h and pb.cc generated files. 我在Ubuntu上安装了Google Protocol Buffers,并编译了.proto文件,所以得到了pb.h和pb.cc生成的文件。
I made ReadAddressBook.cpp very minimal. 我使ReadAddressBook.cpp非常小。 It just creates the proto object and verifies if the version matches.
它只是创建原型对象并验证版本是否匹配。
#include <iostream>
#include <fstream>
#include <string>
#include "address_book.pb.h"
using namespace std;
int main(){
GOOGLE_PROTOBUF_VERIFY_VERSION;
tutorial::AddressBook address_book;
return 0;
}
I compiled it with 我用
g++ -c ReadAddressBook.cpp
(also with g++ -c ReadAddressBook.cpp -lprotobuf -lpthread but it gave the same results) (也可以使用g ++ -c ReadAddressBook.cpp -lprotobuf -lpthread,但结果相同)
However when running: 但是,在运行时:
g++ -o ReadAddressBook ReadAddressBook.o
It gave me the references to the google protobuf src was unavailable. 它给了我对google protobuf src的引用不可用。 Why would this be?
为什么会这样呢?
You need to add -lprotobuf
to the link phase, but it looks like you tried to use it in the compile phase. 您需要将
-lprotobuf
添加到链接阶段,但看起来您试图在编译阶段使用它。 That is, you want to do: 也就是说,您要执行以下操作:
g++ -c ReadAddressBook.cpp
g++ -o ReadAddressBook ReadAddressBook.o -lprotobuf -lpthread
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.