windwos grpc 编译
此文档是windwos grpc c++ 编译 ,基于 vs2015 编译完成
获取gRPC源码
gRPC是开源框架,项目代码在github上,所以首先要安装github。
github安装后,在指定文件夹中,执行Git命令就可以获取gRPC的所有源码。
git clone
https://github.com/grpc/grpc
虽然在github的gRPC主页上提供了源代码打包下载,但是gRPC的依赖组件就无法自动获取了。
获取gRPC的依赖组件
正如所有的项目一样,gRPC也是需要依赖第三方库。由于在gRPC中已经通过git的.gitmodules
文件定义了依赖组件,所以只需执行git命令就可以自动获取所有的依赖组件。
cd grpc
git submodule update --init
(第三方库目录在third_party下面)
vs工程调试
用vs2015打开
vsprojects/grpc.sln
1,删除工程boringssl
2,在\grpc\third_party\zlib\gzguts.h
中将
- #ifdef _WIN32
- # include <stddef.h>
- #endif
改成
- #ifdef _WIN32
- # include <stddef.h>
- #pragma warning(disable:4996)
- #endif
去掉警告。
完成:可以编译
说明:NuGet有还原库,需要等待完成
编译protobuffer
gRPC依赖protobuffer进行消息编码,因此需要依赖protobuffer。(详细见:grpc\third_party\protobuf\cmake\README.md)
需要git,cmake支持
cmd打开vs命令行工具(Windows Desktop Command Prompts/VS2015 x64 x86 兼容工具命令提示符)
cd 到grpc目录
- cd protobuf
- git clone -b release-1.7.0 https://github.com/google/googlemock.git gmock
- cd gmock
- git clone -b release-1.7.0 https://github.com/google/googletest.git gtest
- cd ..\cmake
- mkdir build & cd build
- mkdir release & cd release
- cmake -G "NMake Makefiles" ^
- -DCMAKE_BUILD_TYPE=Release ^
- -DCMAKE_INSTALL_PREFIX=../../../../install ^
- ../..
- cd ..
- mkdir debug & cd debug
- cmake -G "NMake Makefiles" ^
- -DCMAKE_BUILD_TYPE=Debug ^
- -DCMAKE_INSTALL_PREFIX=../../../../install ^
- ../..
- cd ..
- mkdir solution & cd solution
- cmake -G "Visual Studio 14 2015 Win64" ^
- -DCMAKE_INSTALL_PREFIX=../../../../install ^
- ../..
打开grpc\third_party\protobuf\cmake\build\solution下protobuf.sln
编译成功
后续有用到
将编译好的Debug,Release文件夹拷贝到grpc\third_party\protobuf\cmake\目录下(Debug下面的lib文件后边的d需要去掉)
打开grpc\vsprojects\grpc_protoc_plugins.sln编译生成可执行文件
完成
生成文件:
grpc_cpp_plugin.exe
grpc_csharp_plugin.exe
grpc_node_plugin.exe
grpc_objective_c_plugin.exe
grpc_python_plugin.exe
grpc_ruby_plugin.exe
c++生成helloworld服务器程序
1.定义proto
(详细见:grpc\examples\protos\helloworld.proto)
syntax = "proto3";
option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";
option objc_class_prefix = "HLW";
package helloworld;
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
}
2. 生成访问代码
将proto.exe、helloworld.proto、grpc_cpp_plugin.exe拷贝到一个文件夹中,grpc_cpp_plugin.exe是gRPC的protoc插件,生成方法参考上文。
创建一个bat文件,包含以下命令:
protoc.exe -I=. --grpc_out=. --plugin=protoc-gen-grpc=.\grpc_cpp_plugin.exe helloworld.proto
protoc.exe -I=. --cpp_out=. helloworld.proto
生成了两套文件
hellowworld.pb.h 声明生成的消息类的头文件
hellowworld.pb.cc 包含消息类的实现
hellowworld.grpc.pb.h 声明你生成的服务类的头文件
hellowworld.grpc.pb.cc 包含服务类的实现
其中前两个是protoc生成的,后两个是插件生成的。
这些包括:
- 所有的填充,序列化和获取我们请求和响应消息类型的 protocol buffer 代码
- 名为 Greeter的类,包含
- 为了客户端去调用定义在 Greeter服务的远程接口类型(或者 存根 )
- 让服务器去实现的两个抽象接口,同时包括定义在 Greeter中的方法。
详细见:https://doc.oschina.net/grpc?t=57966
生成服务器端代码
3. 创建C++项目
4. 设置头文件
将:grpc\include,grpc\third_party\protobuf\src中的文件拷贝到include目录(自己的库目录)
5. 设置库
grpc\third_party\protobuf\cmake\Release;
grpc\vsprojects\Release;
grpc\third_party\zlib\solution\Release;
grpc\vsprojects\packages\grpc.dependencies.openssl.1.0.204.1\build\native\lib\v120\Win32\Release\static
放入lib目录(自己的lib库目录)
四个库文件路径:protobuf库路径、grpc库路径、zlib库路径、openssl库路径。
没有使用boringssl,openssl的库是从NuGet下载的package中找到的。
库文件
libprotobuf.lib;
grpc.lib;
gpr.lib;
grpc++.lib;
Ws2_32.lib;
6. 编译C++项目
将gRPC的C++ example的代码拷贝到我们刚创建的项目中,编译,出现一些error:
错误A:
error C1189: #error :"Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)"port_platform.h 59 Server_Cpp
解决:在项目属性中的Preprocessor Definitions
中添加_WIN32_WINNT=0x600
错误B:
error C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe - this call relies on the caller to check ****
解决:在项目属性中的Preprocessor Definitions中添加
_SCL_SECURE_NO_WARNINGS
_CRT_SECURE_NO_WARNINGS
错误C:
error LNK2038: mismatch detected for 'RuntimeLibrary': value
解决:只需要主程序和静态库都采用同一种Runtime Libray编译即可。
在项目属性C/C++中的 代码生成 的 运行库 选择 Multi-threaded(/MT)
OpenSSl我是添加的NuGet库来解决的
点击项目右键=>管理NuGet程序包
点击浏览=>输入grpc.dependencies.openssl
找到grpc.dependencies.openssl =>点击安装(我是用的v1.0.204.1版本)
完成,
编辑通过
c++生成helloworld client程序
依照
c++生成helloworld服务器程序
流程,
说明:
附上一个编译好的版本,里面带了测试程序(helloworld)
http://download.csdn.NET/detail/xie1xiao1jun/9630779
windwos grpc 编译的更多相关文章
- grpc编译错误解决
berli@berli-VirtualBox:~/grpc$ make [MAKE] Generating cache.mk [C] Compiling src/core/lib/s ...
- grpc使用记录(一) gRPC编译(mscv/gcc)
目录 1.编译前的准备工作 2.Windows下使用VS2019编译 2.1.使用cmake生成VS2019解决方案 2.2.使用msbuild工具进行编译 3.linux下编译 3.1 CentO ...
- gRPC编译教程
windows平台的编译 一.编译openssl ① 安装perl(可以使用ActivePerl),执行perl Configure VC-WIN64A no-asm .在这里解释一下参数含义,VC- ...
- windwos 下编译minicap
一.参考github 介绍:https://github.com/openstf/minicap Requirements (前提) NDK, Revision 10e (May 2015) make ...
- windwos 下编译 qsqlibase 驱动(firebird 和 interbase)
编译环境:mingw-w64 使用qtcreator打开ibase.pro,ibase.pro位置例如:R:\qt-everywhere-opensource-src-4.8.5\src\plugin ...
- 编译gRPC
编译gRPC 目录 一.概述 二.编译gRPC 三.C#中使用gRPC 四.C++中使用gRPC 无论通过哪种语言调用gRPC,都必须要编译gRPC,因为生成proto访问类时,除了产生标准的数据定义 ...
- 初识google多语言通信框架gRPC系列(二)编译gRPC
目录 一.概述 二.编译gRPC 三.C#中使用gRPC 四.C++中使用gRPC 无论通过哪种语言调用gRPC,都必须要编译gRPC,因为生成proto访问类时,除了产生标准的数据定义类之外,还需要 ...
- grpc vs2015编译
获取gRPC源码 gRPC是开源框架,项目代码在github上,所以首先要安装github.github安装后,在指定文件夹中,执行git命令就可以获取gRPC的所有源码. git clone ht ...
- PHP7 学习笔记(十二)gRPC
GitHub:https://github.com/grpc/grpc/tree/master/src/php 环境:Linux + php7 1.安装grpc pecl install grpc 编 ...
随机推荐
- react+redux状态管理实现排序 合并多个reducer文件
这个demo只有一个reducer 所以合并reducer这个demo用不到 ,但是我写出来这样大家以后可以用到,很好用,管理多个reducer,因为只要用到redux就不会只有一个reducer所以 ...
- 15,Flask-Script
Flask-Script 从字面意思上来看就是 Flask 的脚本 是的,熟悉Django的同学是否还记得Django的启动命令呢? python manager.py runserver 大概是这样 ...
- Eclipse 修改字符集---Eclipse教程第02课
默认情况下 Eclipse 字符集为 GBK,但现在很多项目采用的是 UTF-8,这是我们就需要设置我们的 Eclipse 开发环境字符集为 UTF-8, 设置步骤如下: 在菜单栏选择 Window ...
- Web 开发的未来:React、Falcor 和 ES6
Web 开发的未来:React.Falcor 和 ES6 Widen是一家数字资产管理解决方案提供商.目前,其技术栈还非常传统,包括服务器端的Java.浏览器端的AngularJS.提供REST AP ...
- 剑指Offer - 九度1516 - 调整数组顺序使奇数位于偶数前面
剑指Offer - 九度1516 - 调整数组顺序使奇数位于偶数前面2013-11-30 02:17 题目描述: 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部 ...
- 《Cracking the Coding Interview》——第17章:普通题——题目5
2014-04-28 22:44 题目:猜数字游戏.四个数字,每个都是0~9之间.你每猜一次,我都告诉你,有多少个位置和数字都对(全对),有多少个位置错数字对(半对).比如“6309”,你猜“3701 ...
- 《Cracking the Coding Interview》——第13章:C和C++——题目6
2014-04-25 20:07 题目:为什么基类的析构函数必须声明为虚函数? 解法:不是必须,而是应该,这是种规范.对于基类中执行的一些动态资源分配,如果基类的析构函数不是虚函数,那么 派生类的析构 ...
- QA 、 QC & QM软件测试入门专业名词解释 -- 灌水走起
灌水正式开始: 说明:我的农田,我灌水 一.QA . QC & QM: 1.QM QM 是quanlity management,中文名称是品质管理 2.QA QA是英文quality ass ...
- Struts2+DAO层实现实例02——搭建DAO基本框架并与Struts2组合
实例内容 创建DAO(Data Access Oject)接口:BaseDAO 创建其实例化类:UserDAO 用于获取数据库struts中的userinfo表中的内容 创建User的Java Bea ...
- php + ajax实现 帖子点赞功能
知识: 一.首先页面需要加载jquery框架 二.ajax常用参数解释: ①.type:传输数据方式,get或者post ②.url:处理数据的PHP脚本 ③.data:传输的数据索引及值,值用js获 ...