1、我当前使用的mac OS系统是:
macOS Mojave
Version 10.14.6
2、Command Line Tools:
Xcode Version 11.3.1 (11C504)
3、安装protobuf,
如果你愿意,可以选择源码安装,
我的开发环境采用port管理维护,所以port安装(Centos下使用yum,Ubuntu使用sudo apt-get),安装 protobuf-c protobuf3-cpp,执行命令:
macbook-pro:~ username$ sudo port install protobuf-c
---> Computing dependencies for protobuf-c
The following dependencies will be installed: protobuf3-cpp
Continue? [Y/n]: Y
---> Fetching archive for protobuf3-cpp
---> Attempting to fetch protobuf3-cpp-3.17.3_0.darwin_18.x86_64.tbz2 from https://pek.cn.packages.macports.org/macports/packages/protobuf3-cpp
---> Attempting to fetch protobuf3-cpp-3.17.3_0.darwin_18.x86_64.tbz2.rmd160 from https://pek.cn.packages.macports.org/macports/packages/protobuf3-cpp
---> Installing protobuf3-cpp @3.17.3_0
---> Activating protobuf3-cpp @3.17.3_0
---> Cleaning protobuf3-cpp
---> Fetching archive for protobuf-c
---> Attempting to fetch protobuf-c-1.4.0_0.darwin_18.x86_64.tbz2 from https://pek.cn.packages.macports.org/macports/packages/protobuf-c
---> Attempting to fetch protobuf-c-1.4.0_0.darwin_18.x86_64.tbz2.rmd160 from https://pek.cn.packages.macports.org/macports/packages/protobuf-c
---> Installing protobuf-c @1.4.0_0
---> Activating protobuf-c @1.4.0_0
---> Cleaning protobuf-c
---> Scanning binaries for linking errors
---> No broken files found.
---> No broken ports found.
4、使用protobuf编程,
成功安装后,根据需要,用protoc命令,经demo.proto生成相关的demo.pb.cc和demo.pb.h文件,并编写使用文件,编译,报错“找不到相关文件。。。”,解决方式,引入头文件目录和库文件目录,;
5、使用port安装的程序,头文件安装位置路径/opt/local/include,生成库文件目录/opt/local/lib,在项目工程中添加指定头文件目录和库目录搜索位置,
如图,头文件目录和库目录,
6、快捷键commad+shift+g调出库目录,找到需要的库文件,拖拽到,"Build Phases"->"link Binary With Libraries"项下,如图,



