2018-09-24 vs2015 grpc qt
今天倒騰windows下面grpc編譯以及在qt下面如何簡單實用
1.grpc的編譯工具準備
根據官網說明,安裝下面的相關工具。
Windows
To prepare for cmake + Microsoft Visual C++ compiler build
- Install Visual Studio 2015 or 2017 (Visual C++ compiler will be used).
- Installofollow,noindex">Git .
- InstallCMake .
-
InstallActive State Perl
(
choco install activeperl
) -required by boringssl -
InstallGo
(
choco install golang
) -required by boringssl -
Installyasm
and add it to
PATH
(choco install yasm
) -required by boringssl -
(Optional) InstallNinja
(
choco install ninja
)
2.clone 程式碼庫
Windows
@rem You can also do just "git clone --recursive -b THE_BRANCH_YOU_WANThttps://github.com/grpc/grpc "
git clone --recursive -bhttps://github.com/grpc/grpc.git
cd grpc
@rem To update submodules at later time, run "git submodule update --init"
3.使用cmake編譯
cmake: Windows, Using Visual Studio 2015 or 2017 (can only build with OPENSSL_NO_ASM).When using the "Visual Studio" generator, cmake will generate a solution (grpc.sln) that contains a VS project for every target defined in CMakeLists.txt (+ few extra convenience projects added automatically by cmake). After opening the solution with Visual Studio you will be able to browse and build the code.
@rem Run from grpc directory after cloning the repo with --recursive or updating submodules.md .buildcd .buildcmake .. -G "Visual Studio 14 2015" -DCMAKE_BUILD_TYPE=Releasecmake --build .
由於需要debug版本,只需要將cmake的倒數第二步修改成即可。
cmake .. -G "Visual Studio 14 2015" -DCMAKE_BUILD_TYPE=Debug
編譯過程很順利,沒有什麼錯誤提示。
4.在qt中使用生成的debug以及release庫
下面是自己一步一步嘗試出來的使用的pro檔案,在當前目錄下面建立了staticlib資料夾以及子資料夾debug與release,分別放置debug以及release庫。
自己沒有找到具體include 的lib指導,自己慢慢摸索出來的,有蠻多的坑的。一些簡單的說明
INCLUDEPATH += ../include是拷貝grpc/include下面的所有的標頭檔案
其他的包含庫,只需要按照下面,拷貝生成目錄下面對應的debug以及release檔案即可
DEFINES += _WIN32_WINNT=0x600 是grpc需要的define
QT+= core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = greeter TEMPLATE = app INCLUDEPATH += ../include # The following define makes your compiler emit warnings if you use # any feature of Qt which has been marked as deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if you use deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000# disables all the APIs deprecated before Qt 6.0.0 CONFIG(debug, debug|release) { LIBS += -L$$PWD/staticlib/debug/ -lcares PRE_TARGETDEPS += $$PWD/staticlib/debug/cares.lib LIBS += -L$$PWD/staticlib/debug/ -laddress_sorting PRE_TARGETDEPS += $$PWD/staticlib/debug/address_sorting.lib LIBS += -L$$PWD/staticlib/debug/ -lgpr PRE_TARGETDEPS += $$PWD/staticlib/debug/gpr.lib LIBS += -L$$PWD/staticlib/debug/ -lgrpc PRE_TARGETDEPS += $$PWD/staticlib/debug/grpc.lib LIBS += -L$$PWD/staticlib/debug/ -lgrpc++ PRE_TARGETDEPS += $$PWD/staticlib/debug/grpc++.lib LIBS += -L$$PWD/staticlib/debug/ -llibprotobufd PRE_TARGETDEPS += $$PWD/staticlib/debug/libprotobufd.lib LIBS += -L$$PWD/staticlib/debug/ -lssl PRE_TARGETDEPS += $$PWD/staticlib/debug/ssl.lib LIBS += -L$$PWD/staticlib/debug/ -lcrypto PRE_TARGETDEPS += $$PWD/staticlib/debug/crypto.lib LIBS += -L$$PWD/staticlib/debug/ -ldecrepit PRE_TARGETDEPS += $$PWD/staticlib/debug/decrepit.lib LIBS += -L$$PWD/staticlib/debug/ -lzlibstaticd PRE_TARGETDEPS += $$PWD/staticlib/debug/zlibstaticd.lib } else { LIBS += -L$$PWD/staticlib/release/ -lcares PRE_TARGETDEPS += $$PWD/staticlib/release/cares.lib LIBS += -L$$PWD/staticlib/release/ -laddress_sorting PRE_TARGETDEPS += $$PWD/staticlib/release/address_sorting.lib LIBS += -L$$PWD/staticlib/release/ -lgpr PRE_TARGETDEPS += $$PWD/staticlib/release/gpr.lib LIBS += -L$$PWD/staticlib/release/ -lgrpc PRE_TARGETDEPS += $$PWD/staticlib/release/grpc.lib LIBS += -L$$PWD/staticlib/release/ -lgrpc++ PRE_TARGETDEPS += $$PWD/staticlib/release/grpc++.lib LIBS += -L$$PWD/staticlib/release/ -llibprotobuf PRE_TARGETDEPS += $$PWD/staticlib/release/libprotobuf.lib LIBS += -L$$PWD/staticlib/release/ -lssl PRE_TARGETDEPS += $$PWD/staticlib/release/ssl.lib LIBS += -L$$PWD/staticlib/release/ -lcrypto PRE_TARGETDEPS += $$PWD/staticlib/release/crypto.lib LIBS += -L$$PWD/staticlib/release/ -ldecrepit PRE_TARGETDEPS += $$PWD/staticlib/release/decrepit.lib LIBS += -L$$PWD/staticlib/release/ -lzlibstatic PRE_TARGETDEPS += $$PWD/staticlib/release/zlibstatic.lib } LIBS += -lWs2_32 -ladvapi32 INCLUDEPATH += $$PWD/include DEFINES += _WIN32_WINNT=0x600 SOURCES += \ main.cpp \ mainwindow.cpp \ greeter_server.cc \ helloworld.grpc.pb.cc \ helloworld.pb.cc HEADERS += \ mainwindow.h \ helloworld.grpc.pb.h \ helloworld.pb.h \ greeter_client.h FORMS += \ mainwindow.ui
ok