![](/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.