tuxmartin

c++ protobuf test

Feb 11th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1. /*
  2. g++ -std=c++0x -D__cplusplus=201103L -I/usr/local/include -O0 -g3 -Wall -Wextra -pedantic -c -fmessage-length=0 -MMD -MP -o "Test.o" "Test.cpp"
  3. g++ -o "test" Test.o -pthread -lprotobuf -lpthread -L/usr/local/lib -pedantic
  4. */ 
  5.  
  6. #include <string>
  7. #include <iostream>
  8. #include <fstream>
  9.  
  10. // ProtocolBuffers
  11. #include "Combined.pb.h"
  12.  
  13. using namespace std;
  14. using namespace AngeeProtobuf;
  15.  
  16. void ListUsers(const Presence& p) {
  17.     cout << "USER PRESENCE DATA_SIZE: " << p.data_size() << endl;
  18.     for (int i = 0; i < p.data_size(); i++) {
  19.         const User& u = p.data(i);
  20.         cout << "USER PRESENCE: " << u.username() << ", online: " << u.online() << ", stateChanged: " << u.statechanged() << endl;
  21.     }  
  22. }
  23.  
  24. int main(int argc, char* argv[]) {
  25.    
  26.     if (argc != 2) {
  27.         cerr << "Usage:  " << argv[0] << " PRESENCE_PROTO_FILE" << endl;
  28.         return -1;
  29.     }
  30.    
  31.     Presence p;
  32.  
  33.     // Read Presence
  34.     fstream input(argv[1], ios::in | ios::binary);
  35.     if (!p.ParseFromIstream(&input)) {
  36.         cerr << "Failed to parse Presence." << endl;
  37.         return -1;
  38.     }
  39.  
  40.     ListUsers(p);
  41. }
  42.  
  43.  
  44.  
  45.  
  46. martin@meo2:~/protobuf_test$ g++ -std=c++0x -D__cplusplus=201103L -I/usr/local/include -O0 -g3 -Wall -Wextra -pedantic -c -fmessage-length=0 -MMD -MP -o "Test.o" "Test.cpp"
  47. martin@meo2:~/protobuf_test$ g++ -o "test" Test.o -pthread -lprotobuf -lpthread -L/usr/local/lib -pedantic
  48. Test.o: In function `main':
  49. /home/martin/protobuf_test/Test.cpp:31: undefined reference to `AngeeProtobuf::Presence::Presence()'
  50. /home/martin/protobuf_test/Test.cpp:34: undefined reference to `AngeeProtobuf::Presence::~Presence()'
  51. /home/martin/protobuf_test/Test.cpp:31: undefined reference to `AngeeProtobuf::Presence::~Presence()'
  52. collect2: error: ld returned 1 exit status
  53. martin@meo2:~/protobuf_test$
Advertisement
Add Comment
Please, Sign In to add comment