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 编 ...
随机推荐
- qq登录面板
- 《Cracking the Coding Interview》——第5章:位操作——题目2
2014-03-19 05:47 题目:给定一个double型浮点数,输出其二进制表示,如果不能在32个字符内完成输出,则输出“ERROR”. 解法:如果你熟悉IEEE754标准,应该知道double ...
- python学习笔记五:模块和包
一.模块用import导入 cal.py: #!/usr/bin/python def add(x,y): return x+y if __name__ == '__main__': print ad ...
- 如何将现有的项目添加到远程的git库里面!
我们经常都会遇到这样的场景,就是将本地的一个项目同步到网上远程的git库里面.最近也遇到这样的问题,发现网上很少人讲到这个问题,但是这个问题是很多程序员遇到的版本库管理的最早的拦路虎. 我的远程是ht ...
- Python之日志处理 logging模块
Python之日志处理(logging模块) 本节内容 日志相关概念 logging模块简介 使用logging提供的模块级别的函数记录日志 logging模块日志流处理流程 使用logging四 ...
- sources.list
deb http://debian.ustc.edu.cn/ubuntu/ precise main multiverse restricted universe deb http://debian. ...
- matlab使用摄像头人脸识别
#关于matlab如何读取图片.视频.摄像头设备数据# 参见:http://blog.csdn.net/u010177286/article/details/45646173 但是,关于摄像头读取,上 ...
- OpenCV_1.0安装包下载
OpenCV_1.0安装包下载 点击下载
- [常识]Windows系统里休眠和睡眠的区别?
睡眠和休眠都是笔记本电脑的节能方式,但有细微的差别: 睡眠还保持着开机状态的,休眠是关机了,但是再次开机之后和关闭时的系统状态是一样的. 睡眠还是保持着系统运行数据在内存中,而休眠则将内存中的数据保存 ...
- opencv3.1+cmake+mingw5.3+QT5编译
太不容易了! 想要访问opencv的官网貌似要FQ才行.下载了opencv3.2版本,发现cmake在download opencv_ffmpeg.dll的地方超时了. 于是搜索一番,发现很多编译op ...