Protobuf3编译纠错

Protobuf3编译纠错

2018年07月12日 19:44:05 一方风景 阅读数:448

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/TifferPelode/article/details/81021251

博主环境是Ubuntu 16.04  x86架构

最近在学习Google的Protobuf通讯协议,在编译一个例程的过程中出现了大量未定义引用。

 
  1. In file included from /usr/local/include/google/protobuf/stubs/common.h:52:0,

  2. from test.pb.h:9,

  3. from test.cpp:3:

  4. /usr/local/include/google/protobuf/stubs/mutex.h:58:8: error: ‘mutex’ in namespace ‘std’ does not name a type

  5. std::mutex mu_;

这是原本的命令行:

g++ test.cpp test.pb.cc -o t -lprotobuf -lpthread

经查校后,发现是引用不全导致的,正确编译命令应为:

g++ test.cpp test.pb.cc -o t -std=c++11 -I /usr/local/include/ -L /usr/local/lib/ -lprotobuf -lpthread

相较于命令行编译,推荐使用cmake来进行编译。

猜你喜欢

转载自blog.csdn.net/lusic01/article/details/88354935