[Raspberry pi] 編譯 GRPC
最近在嘗試網路連線部分,想說Google出了一套GRPC的通訊感覺很好用就來用看看~
首先先下載所需要的工具
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
並存檔後離開,並執行指令使配置文件修改生效
libprotoc 3.4.0
接著就來安裝grpc吧!
進入到grpc的資料夾
編譯看看範例程式是否安裝成功,make產生測試執行檔
Server listening on 0.0.0.0:50051
接著啟動 client 端
Greeter received: Hello world
恭喜你,成功囉~
在編譯grpc的過程中我遇到兩個錯誤
請參閱 https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes#Downloads
處理方法:
發生這種情況是因為Makefile在構建插件時使用系統libprotobuf庫,而不是使用/ usr / local / lib中安裝的protobuf庫。
處理方法:
將他修改成 HOST_LDLIBS_PROTOC += -L/usr/local/lib $(addprefix -l, $(LIBS_PROTOC))
存檔後離開,之後再執行
參考資料:
https://grpc.io/docs/quickstart/cpp.html#build-the-example
http://blog.csdn.net/guoyilongedu/article/details/17093811
https://github.com/grpc/grpc/issues/10589
https://github.com/grpc/grpc/issues/9549
首先先下載所需要的工具
$ sudo apt-get install build-esstial autoconf libtool $ sudo apt-get install libgtest-dev clang libc++-dev $ sudo apt-get install git cmake vim make接著利用git下載原始碼
$ git clone https://github.com/grpc/grpc.git
因為grpc依賴protobuf,所以要先安裝protobuf$ cd grpc/third_party
由於git下來的protobuf資料節是空的所以要再將protobuf git下來grpc/third_party $ git clone https://github.com/google/protobuf.git grpc/third_party $ cd protobuf透過執行 autogen.sh 生成 configure 檔
grpc/third_party/protobuf $ ./autogen.sh grpc/third_party/protobuf $ ./configure grpc/third_party/protobuf $ make -j4 grpc/third_party/protobuf $ make check grpc/third_party/protobuf $ sudo make install grpc/third_party/protobuf $ sudo ldconfig基本上這樣就安裝好了,但還需要做一些環境設定
$ vim ~/.profile
利用vim打開該文件後,在最下面新增這行export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
並存檔後離開,並執行指令使配置文件修改生效
$ source ~/.profile
查看protobuf版本以測試是否安装成功$ protoc --version
我裝的版本是libprotoc 3.4.0,所以會顯示libprotoc 3.4.0
接著就來安裝grpc吧!
進入到grpc的資料夾
$ cd grpc grpc $ git submodule update --init grpc $ make -j4 grpc $ make check grpc $ sudo make install grpc $ sudo ldconfig這樣就安裝好了喔!
編譯看看範例程式是否安裝成功,make產生測試執行檔
grpc $ cd examples/cpp/helloworld/ grpc/examples/cpp/helloworld/ $ make執行看看吧,先啟動 server 端
grpc/examples/cpp/helloworld/ $ ./greeter_server
成功執行會看到Server listening on 0.0.0.0:50051
接著啟動 client 端
grpc/examples/cpp/helloworld/ $ ./greeter_client
看到Greeter received: Hello world
恭喜你,成功囉~
在編譯grpc的過程中我遇到兩個錯誤
問題1. gRPC不再使用OpenSSL構建 - 僅在Debian下
這是我出現錯誤時螢幕上所顯示的 errorsrc/core/tsi/ssl_transport_security.c: In function ‘tsi_create_ssl_client_handshaker_factory’:
src/core/tsi/ssl_transport_security.c:1356:3: error: ‘TLSv1_2_method’ is deprecated [-Werror=deprecated-declarations]
ssl_context = SSL_CTX_new(TLSv1_2_method());
^~~~~~~~~~~
In file included from /usr/include/openssl/ct.h:13:0,
from /usr/include/openssl/ssl.h:61,
from src/core/tsi/ssl_transport_security.c:45:
/usr/include/openssl/ssl.h:1624:1: note: declared here
DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_2_method(void)) /* TLSv1.2 */
^
src/core/tsi/ssl_transport_security.c: In function ‘tsi_create_ssl_server_handshaker_factory_ex’:
src/core/tsi/ssl_transport_security.c:1473:7: error: ‘TLSv1_2_method’ is deprecated [-Werror=deprecated-declarations]
impl->ssl_contexts[i] = SSL_CTX_new(TLSv1_2_method());
^~~~
In file included from /usr/include/openssl/ct.h:13:0,
from /usr/include/openssl/ssl.h:61,
from src/core/tsi/ssl_transport_security.c:45:
/usr/include/openssl/ssl.h:1624:1: note: declared here
DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_2_method(void)) /* TLSv1.2 */
^
At top level:
src/core/tsi/ssl_transport_security.c:126:22: error: ‘openssl_thread_id_cb’ defined but not used [-Werror=unused-function]
static unsigned long openssl_thread_id_cb(void) {
^~~~~~~~~~~~~~~~~~~~
src/core/tsi/ssl_transport_security.c:118:13: error: ‘openssl_locking_cb’ defined but not used [-Werror=unused-function]
static void openssl_locking_cb(int mode, int type, const char *file, int line) {
^~~~~~~~~~~~~~~~~~
[C] Compiling src/core/ext/transport/chttp2/server/chttp2_server.c
[C] Compiling src/core/ext/transport/chttp2/client/secure/secure_channel_create.c
[C] Compiling src/core/ext/filters/client_channel/channel_connectivity.c
[C] Compiling src/core/ext/filters/client_channel/client_channel.c
[C] Compiling src/core/ext/filters/client_channel/client_channel_factory.c
[C] Compiling src/core/ext/filters/client_channel/client_channel_plugin.c
[C] Compiling src/core/ext/filters/client_channel/connector.c
[C] Compiling src/core/ext/filters/client_channel/http_connect_handshaker.c
cc1: all warnings being treated as errors
[C] Compiling src/core/ext/filters/client_channel/http_proxy.c
Makefile:2564: recipe for target '/home/pi/Downloads/grpc/objs/opt/src/core/tsi/ssl_transport_security.o' failed
make: *** [/home/pi/Downloads/grpc/objs/opt/src/core/tsi/ssl_transport_security.o] Error 1
make: *** Waiting for unfinished jobs....
會造成這個問題是這個版本的Debian隨OpenSSL 1.1一起發行,這個API已經發生了重大的變化。請參閱 https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes#Downloads
處理方法:
$ sudo apt-get remove libssl1.1
$ sudo apt-get instal libssl1.0
之後再執行grpc $ make clean
grpc $ make -j4
就會順利完成了喔!問題2. libprotobuf
這是我出現的 error//usrusr/usr/bin/ld: warning: libprotobuf.so.14, /needed by //usr/bin/ldlocal/lib/libprotoc.so, :may warning: /bin/ld: warning: libprotobuf.so.14, needed by //usr/local/lib/libprotoc.so,libprotobuf.so.14 may conflict with , conflict with libprotobuf.so.10 /usr/bin/ld: warning: libprotobuf.so.14, needed by //usr/local/lib/libprotoc.so, may conflict with libprotobuf.so.10 /usr/bin/ld: /home/pi/Downloads/grpc/libs/opt/libgrpc_plugin_support.a(objective_c_generator.o): undefined reference to symbol '_ZNK6google8protobuf16MethodDescriptor11output_typeEv' /usr/local/lib/libprotobuf.so.14: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status Makefile:15381: recipe for target '/home/pi/Downloads/grpc/bins/opt/grpc_objective_c_plugin' failed make: *** [/home/pi/Downloads/grpc/bins/opt/grpc_objective_c_plugin] Error 1 make: *** Waiting for unfinished jobs.... libprotobuf.so.10 /usr/bin/ld: warning: libprotobuf.so.14, needed by /needed/usr/local/lib/libprotoc.so, may conflict with by /libprotobuf.so.10/usr /usr/bin//ld: /localhome/pi//Downloads/grpc/libs/opt/libgrpc_plugin_support.a(csharp_generator.o): undefined reference to symbol '_ZNK6google8protobuf16MethodDescriptor11output_typeEv' /usr/local/liblib/libprotobuf.so.14: error adding symbols/:libprotoc.so DSO missing from command, line may conflict with libprotobuf.so.10 /usr/bin/ld: collect2: error: ld returned 1 exit status warning: libprotobuf.so.14, needed by //usr/local/lib/libprotoc.so, may conflict with libprotobuf.so.10 /usr/bin/ld: /home/pi/Downloads/grpc/libs/opt/libgrpc_plugin_support.a(node_generator.o): undefined reference to symbol '_ZNK6google8protobuf16MethodDescriptor11output_typeEv' /usr/Makefile:15319: recipe for target '/home/pi/Downloads/grpc/bins/opt/grpc_csharp_plugin' failed local/make: *** [/home/pi/Downloads/grpc/bins/opt/grpc_csharp_plugin] Error 1 lib/libprotobuf.so.14: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status Makefile:15350: recipe for target '/home/pi/Downloads/grpc/bins/opt/grpc_node_plugin' failed make: *** [/home/pi/Downloads/grpc/bins/opt/grpc_node_plugin] Error 1
發生這種情況是因為Makefile在構建插件時使用系統libprotobuf庫,而不是使用/ usr / local / lib中安裝的protobuf庫。
處理方法:
grpc $ vim Makefile
$ sudo apt-get instal libssl1.0
找到 HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC))將他修改成 HOST_LDLIBS_PROTOC += -L/usr/local/lib $(addprefix -l, $(LIBS_PROTOC))
存檔後離開,之後再執行
grpc $ make clean
grpc $ make -j4
參考資料:
https://grpc.io/docs/quickstart/cpp.html#build-the-example
http://blog.csdn.net/guoyilongedu/article/details/17093811
https://github.com/grpc/grpc/issues/10589
https://github.com/grpc/grpc/issues/9549
留言
張貼留言