參考readme用CMAKE生成工程文件,編譯便可。首先打開vs2015開發人員命令提示符窗口,切換到對應的protobuf目錄css
具體步驟:nginx
1:cd protobufc++
2: Git clone -b release-1.7.0 https://github.com/google/googlemock.git gmockgit
3:cd gmockgithub
4:git clone -b release-1.7.0 https://github.com/google/googletest.git gtestsql
5:cd ..\cmakeruby
6:mkdir build & cd build & mkdir install網絡
7:mkdir debug & cd debug多線程
8:cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../install ../..框架
9:nmake && nmake install
10:生成完成,在install目錄下面有對應的Lib文件。在cmake目錄下面mkdir debug,而後把install/lib目錄下的全部庫文件拷貝的debug路徑,並把後綴d去掉。例如protobuf生成的庫名稱爲libprotocd.lib,應該更名成libprotoc.lib。其餘的依次類推。後面編譯grpc會用到這些庫。
step2. 編譯grpc,grpc_protoc_plugin:在vsprojects裏有建好的工程文件,下載nuget.exe,用於依賴包的網絡下載。主要是依賴於openssl和zlib庫。在編譯grpc時,出現編譯boringssl,出現不少錯誤,能夠把工程移除
具體步驟:
1:cd vsprojects
2:nuget restore grpc.sln
3:msbuild grpc.sln /p:Configuration=Debug
grpc庫生成成功。
4:編譯grpc_cpp_plugin,執行命令:msbuild grpc_protoc_plugins.sln /p:Configuration=Debug
grpc_cpp_plugin.exe插件編譯成功
用vs2015編譯基本不會遇到什麼問題,除了:grpc_cpp_plugin依賴libprotoc.lib,而protobuf生成的庫名稱爲libprotocd.lib,這塊須要手動改一下
step3. zlib 參考readme
step4編譯helloworld
1: cd grpc/example/protos
2: 把proto.exe(protobuf工程生成,在install/bin目錄下)、helloworld.proto拷貝到vsprojects\debug路徑下面。此時在vsprojects\debug路徑下面執行命令
3:在vsprojects目錄建立空的WIN32 C++工程grpc_helloworld.sln,在目錄grpc_helloworld下面有兩個文件夾。目錄結構以下圖
解決:在項目屬性中的Preprocessor Definitions
中添加_WIN32_WINNT=0x600
Error 1 error C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators' c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility 2132 1 Server_Cpp
解決:在項目屬性中的Preprocessor Definitions中添加
_SCL_SECURE_NO_WARNINGS _CRT_SECURE_NO_WARNINGS
error LNK2038: mismatch detected for 'RuntimeLibrary': value
解決:只須要主程序和靜態庫都採用同一種Runtime Libray編譯便可。
在項目屬性C/C++中的Code Generation的Runtime Library選擇Multi-threaded(/MT)
Error 2 error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MTd_StaticDebug' in greeter_server.obj D:\Projects_My\gRPC\gRPC_cpp\Server_Cpp\libprotobuf.lib(generated_message_util.obj) Server_Cpp
解決:緣由是將debug的配置拷貝到release時,將Preprocessor Definitions的_DEBUG也考到release中了,去掉_DEBUG便可
Error 113 error LNK2001: unresolved external symbol _SSL_state D:\Projects_My\gRPC\gRPC_cpp\Server_Cpp\grpc.lib(ssl_transport_security.obj) Server_Cpp
解決:添加openssl的lib(用v120,多是vs的版本號),具體用v1xx能夠根據本身的vs版原本對應
D:\XXXX\grpc\vsprojects\packages\grpc.dependencies.openssl.1.0.204.1\build\native\lib\v120\Win32\Release\static
庫文件:
libeay32.lib ssleay32.lib
Error 2 error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj) D:\Projects_My\gRPC\gRPC_cpp\Server_Cpp\msvcrt.lib(ti_inst.obj) Server_Cpp
解決:
Project Settings:
-> Configration Properties -> Linker -> Input -> Ignore Specific Library: LIBCMT.lib
在編譯的時候,有能夠還會遇到找不到Grpc內的某個符號,好比Channel、Complete_quque等, 如下以channel爲例說明解決方法:
GRPC編譯grpc++.lib時,生成的Channel.obj會被覆蓋(緣由沒查出來,大概是由於grpc.lib編譯時一樣會生成channel.obj)
刪掉obj目錄中C:\path\to\grpc\vsprojects\IntDir\grpc++中的channel.obj,而後在工程裏「生成」(不要從新生成)