栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

xcode c++ 编程使用protobuf

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

xcode c++ 编程使用protobuf

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"项下,如图,

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/302957.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号