![](/img/trans.png)
[英]Integrate Google Protocol Buffers .proto files to Visual C++ 2010
[英]C++ Linux Google Protocol Buffers - cannot run compiled proto cpp files from tutorial
我正在关注Google协议缓冲区的cpp教程
我在Ubuntu上安装了Google Protocol Buffers,并编译了.proto文件,所以得到了pb.h和pb.cc生成的文件。
我使ReadAddressBook.cpp非常小。 它只是创建原型对象并验证版本是否匹配。
#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;
}
我用
g++ -c ReadAddressBook.cpp
(也可以使用g ++ -c ReadAddressBook.cpp -lprotobuf -lpthread,但结果相同)
但是,在运行时:
g++ -o ReadAddressBook ReadAddressBook.o
它给了我对google protobuf src的引用不可用。 为什么会这样呢?
您需要将-lprotobuf
添加到链接阶段,但看起来您试图在编译阶段使用它。 也就是说,您要执行以下操作:
g++ -c ReadAddressBook.cpp
g++ -o ReadAddressBook ReadAddressBook.o -lprotobuf -lpthread
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.