简体   繁体   English

无法编译 grpc c++ helloworld 示例

[英]Cannot compile grpc c++ helloworld example

I use Ubuntu 20.04 with the following OpenSSL version:我使用 Ubuntu 20.04 和以下 OpenSSL 版本:

nirupamix@nirupamix:~grpc/examples/cpp/helloworld/cmake/build ((v1.41.1))$ openssl version
OpenSSL 1.1.1f  31 Mar 2020

I installed grpc (v.1.41.1) from github with cmake/make/make install, and then tried to compile example/cpp/helloworld.我使用 cmake/make/make install 从 github 安装了 grpc (v.1.41.1),然后尝试编译 example/cpp/helloworld。 I got an error involving OpenSSL that I can't manage to work out:我遇到了一个涉及 OpenSSL 的错误,我无法解决:

nirupamix@nirupamix:~/grpc/examples/cpp/helloworld/cmake/build ((v1.41.1))$ make
[  5%] Generating helloworld.pb.cc, helloworld.pb.h, helloworld.grpc.pb.cc, helloworld.grpc.pb.h
Scanning dependencies of target hw_grpc_proto
[ 11%] Building CXX object CMakeFiles/hw_grpc_proto.dir/helloworld.grpc.pb.cc.o
[ 16%] Building CXX object CMakeFiles/hw_grpc_proto.dir/helloworld.pb.cc.o
[ 22%] Linking CXX static library libhw_grpc_proto.a
[ 22%] Built target hw_grpc_proto
Scanning dependencies of target greeter_async_client2
[ 27%] Building CXX object CMakeFiles/greeter_async_client2.dir/greeter_async_client2.cc.o
[ 33%] Linking CXX executable greeter_async_client2
/usr/bin/ld: /usr/local/lib/libgrpc.a(json_token.cc.o): in function `compute_and_encode_signature(grpc_auth_json_key const*, char const*, char const*)':
json_token.cc:(.text+0xedb): undefined reference to `EVP_MD_CTX_create'
/usr/bin/ld: json_token.cc:(.text+0xf98): undefined reference to `EVP_DigestSignUpdate'
/usr/bin/ld: json_token.cc:(.text+0x10a5): undefined reference to `EVP_MD_CTX_destroy'
/usr/bin/ld: /usr/local/lib/libgrpc.a(ssl_transport_security.cc.o): in function `init_openssl()':
ssl_transport_security.cc:(.text+0x32): undefined reference to `SSL_CTX_get_ex_new_index'
/usr/bin/ld: /usr/local/lib/libgrpc.a(ssl_transport_security.cc.o): in function `peer_property_from_x509_common_name(x509_st*, tsi_peer_property*)':
ssl_transport_security.cc:(.text+0x5c5): undefined reference to `OPENSSL_free'
/usr/bin/ld: /usr/local/lib/libgrpc.a(ssl_transport_security.cc.o): in function `add_pem_certificate(x509_st*, tsi_peer_property*)':
ssl_transport_security.cc:(.text+0x654): undefined reference to `BIO_get_mem_data'
/usr/bin/ld: /usr/local/lib/libgrpc.a(ssl_transport_security.cc.o): in function `add_subject_alt_names_properties_to_peer(tsi_peer*, stack_st_GENERAL_NAME*, unsigned long, int*)':
ssl_transport_security.cc:(.text+0x8f3): undefined reference to `OPENSSL_free'
/usr/bin/ld: ssl_transport_security.cc:(.text+0x96f): undefined reference to `OPENSSL_free'
/usr/bin/ld: /usr/local/lib/libgrpc.a(ssl_transport_security.cc.o): in function `ssl_ctx_use_certificate_chain(ssl_ctx_st*, char const*, unsigned long)':
ssl_transport_security.cc:(.text+0x12e8): undefined reference to `SSL_CTX_add_extra_chain_cert'
/usr/bin/ld: /usr/local/lib/libgrpc.a(ssl_transport_security.cc.o): in function `populate_ssl_context(ssl_ctx_st*, tsi_ssl_pem_key_cert_pair const*, char const*)':
ssl_transport_security.cc:(.text+0x192f): undefined reference to `SSL_CTX_set_tmp_ecdh'
/usr/bin/ld: /usr/local/lib/libgrpc.a(ssl_transport_security.cc.o): in function `tsi_set_min_and_max_tls_versions(ssl_ctx_st*, tsi_tls_version, tsi_tls_version)':
ssl_transport_security.cc:(.text+0x1cf0): undefined reference to `SSL_CTX_set_min_proto_version'
/usr/bin/ld: ssl_transport_security.cc:(.text+0x1d03): undefined reference to `SSL_CTX_set_min_proto_version'
/usr/bin/ld: ssl_transport_security.cc:(.text+0x1d4d): undefined reference to `SSL_CTX_set_max_proto_version'
/usr/bin/ld: ssl_transport_security.cc:(.text+0x1d60): undefined reference to `SSL_CTX_set_max_proto_version'
/usr/bin/ld: /usr/local/lib/libgrpc.a(ssl_transport_security.cc.o): in function `ssl_protector_protect(tsi_frame_protector*, unsigned char const*, unsigned long*, unsigned char*, unsigned long*)':
ssl_transport_security.cc:(.text+0x2040): undefined reference to `BIO_pending'
/usr/bin/ld: /usr/local/lib/libgrpc.a(ssl_transport_security.cc.o): in function `ssl_protector_protect_flush(tsi_frame_protector*, unsigned char*, unsigned long*, unsigned long*)':
ssl_transport_security.cc:(.text+0x233a): undefined reference to `BIO_pending'
/usr/bin/ld: ssl_transport_security.cc:(.text+0x2453): undefined reference to `BIO_pending'
/usr/bin/ld: /usr/local/lib/libgrpc.a(ssl_transport_security.cc.o): in function `tsi_ssl_get_cert_chain_contents(stack_st_X509*, tsi_peer_property*)':
ssl_transport_security.cc:(.text+0x28b4): undefined reference to `BIO_get_mem_data'
/usr/bin/ld: /usr/local/lib/libgrpc.a(ssl_transport_security.cc.o): in function `ssl_handshaker_get_bytes_to_send_to_peer(tsi_ssl_handshaker*, unsigned char*, unsigned long*)':
ssl_transport_security.cc:(.text+0x2ff8): undefined reference to `BIO_should_retry'
/usr/bin/ld: ssl_transport_security.cc:(.text+0x3039): undefined reference to `BIO_pending'
/usr/bin/ld: /usr/local/lib/libgrpc.a(ssl_transport_security.cc.o): in function `ssl_handshaker_process_bytes_from_peer(tsi_ssl_handshaker*, unsigned char const*, unsigned long*)':
ssl_transport_security.cc:(.text+0x327f): undefined reference to `BIO_pending'
/usr/bin/ld: /usr/local/lib/libgrpc.a(ssl_transport_security.cc.o): in function `ssl_bytes_remaining(tsi_ssl_handshaker*, unsigned char**, unsigned long*)':
ssl_transport_security.cc:(.text+0x33de): undefined reference to `BIO_pending'
/usr/bin/ld: /usr/local/lib/libgrpc.a(ssl_transport_security.cc.o): in function `create_tsi_ssl_handshaker(ssl_ctx_st*, int, char const*, tsi_ssl_handshaker_factory*, tsi_handshaker**)':
ssl_transport_security.cc:(.text+0x3918): undefined reference to `SSL_set_tlsext_host_name'
/usr/bin/ld: /usr/local/lib/libgrpc.a(ssl_transport_security.cc.o): in function `tsi_create_ssl_client_handshaker_factory_with_options(tsi_ssl_client_handshaker_options const*, tsi_ssl_client_handshaker_factory**)':
ssl_transport_security.cc:(.text+0x4739): undefined reference to `SSL_CTX_set_session_cache_mode'
/usr/bin/ld: /usr/local/lib/libgrpc.a(ssl_transport_security.cc.o): in function `tsi_create_ssl_server_handshaker_factory_with_options(tsi_ssl_server_handshaker_options const*, tsi_ssl_server_handshaker_factory**)':
ssl_transport_security.cc:(.text+0x4e1a): undefined reference to `SSL_CTX_set_tlsext_ticket_keys'
/usr/bin/ld: ssl_transport_security.cc:(.text+0x5073): undefined reference to `SSL_CTX_set_tlsext_servername_callback'
/usr/bin/ld: ssl_transport_security.cc:(.text+0x5098): undefined reference to `SSL_CTX_set_tlsext_servername_arg'
/usr/bin/ld: /usr/local/lib/libgrpc.a(ssl_transport_security.cc.o): in function `sk_X509_NAME_new_null':
ssl_transport_security.cc:(.text.sk_X509_NAME_new_null[sk_X509_NAME_new_null]+0x9): undefined reference to `sk_new_null'
/usr/bin/ld: /usr/local/lib/libgrpc.a(ssl_transport_security.cc.o): in function `sk_X509_NAME_pop_free':
ssl_transport_security.cc:(.text.sk_X509_NAME_pop_free[sk_X509_NAME_pop_free]+0x2a): undefined reference to `sk_pop_free_ex'
/usr/bin/ld: /usr/local/lib/libgrpc.a(ssl_transport_security.cc.o): in function `sk_X509_NAME_push':
ssl_transport_security.cc:(.text.sk_X509_NAME_push[sk_X509_NAME_push]+0x23): undefined reference to `sk_push'
/usr/bin/ld: /usr/local/lib/libgrpc.a(ssl_transport_security.cc.o): in function `sk_X509_num':
ssl_transport_security.cc:(.text.sk_X509_num[sk_X509_num]+0x18): undefined reference to `sk_num'
/usr/bin/ld: /usr/local/lib/libgrpc.a(ssl_transport_security.cc.o): in function `sk_X509_value':
ssl_transport_security.cc:(.text.sk_X509_value[sk_X509_value]+0x23): undefined reference to `sk_value'
/usr/bin/ld: /usr/local/lib/libgrpc.a(ssl_transport_security.cc.o): in function `sk_GENERAL_NAME_num':
ssl_transport_security.cc:(.text.sk_GENERAL_NAME_num[sk_GENERAL_NAME_num]+0x18): undefined reference to `sk_num'
/usr/bin/ld: /usr/local/lib/libgrpc.a(ssl_transport_security.cc.o): in function `sk_GENERAL_NAME_value':
ssl_transport_security.cc:(.text.sk_GENERAL_NAME_value[sk_GENERAL_NAME_value]+0x23): undefined reference to `sk_value'
/usr/bin/ld: /usr/local/lib/libgrpc.a(ssl_transport_security.cc.o): in function `sk_GENERAL_NAME_pop_free':
ssl_transport_security.cc:(.text.sk_GENERAL_NAME_pop_free[sk_GENERAL_NAME_pop_free]+0x2a): undefined reference to `sk_pop_free_ex'
/usr/bin/ld: /usr/local/lib/libgrpc.a(aes_gcm.cc.o): in function `aes_gcm_get_openssl_errors()':
aes_gcm.cc:(.text+0x57): undefined reference to `BIO_get_mem_ptr'
/usr/bin/ld: /usr/local/lib/libcrypto.a(dso_dlfcn.o): in function `dlfcn_globallookup':
dso_dlfcn.c:(.text+0x17): undefined reference to `dlopen'
/usr/bin/ld: dso_dlfcn.c:(.text+0x2a): undefined reference to `dlsym'
/usr/bin/ld: dso_dlfcn.c:(.text+0x35): undefined reference to `dlclose'
/usr/bin/ld: /usr/local/lib/libcrypto.a(dso_dlfcn.o): in function `dlfcn_bind_func':
dso_dlfcn.c:(.text+0x1b7): undefined reference to `dlsym'
/usr/bin/ld: dso_dlfcn.c:(.text+0x282): undefined reference to `dlerror'
/usr/bin/ld: /usr/local/lib/libcrypto.a(dso_dlfcn.o): in function `dlfcn_load':
dso_dlfcn.c:(.text+0x2f5): undefined reference to `dlopen'
/usr/bin/ld: dso_dlfcn.c:(.text+0x369): undefined reference to `dlclose'
/usr/bin/ld: dso_dlfcn.c:(.text+0x3a5): undefined reference to `dlerror'
/usr/bin/ld: /usr/local/lib/libcrypto.a(dso_dlfcn.o): in function `dlfcn_pathbyaddr':
dso_dlfcn.c:(.text+0x466): undefined reference to `dladdr'
/usr/bin/ld: dso_dlfcn.c:(.text+0x4d7): undefined reference to `dlerror'
/usr/bin/ld: /usr/local/lib/libcrypto.a(dso_dlfcn.o): in function `dlfcn_unload':
dso_dlfcn.c:(.text+0x6b8): undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/greeter_async_client2.dir/build.make:127: greeter_async_client2] Error 1
make[1]: *** [CMakeFiles/Makefile2:90: CMakeFiles/greeter_async_client2.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

Has anyone ever encountered anything like this?有没有人遇到过这样的事情? Thanks in advance!提前致谢!

Did you try to follow the quick start guide ?您是否尝试遵循快速入门指南

It worked perfectly for me.它对我来说非常有效。

  • Setup Choose a directory to hold locally installed packages.安装 选择一个目录来保存本地安装的包。 This page assumes that the environment variable MY_INSTALL_DIR holds this directory path.此页面假定环境变量 MY_INSTALL_DIR 保存此目录路径。 For example:例如:

    $ export MY_INSTALL_DIR=$HOME/.local $ export MY_INSTALL_DIR=$HOME/.local

Ensure that the directory exists:确保目录存在:

 $ mkdir -p $MY_INSTALL_DIR

Add the local bin folder to your path variable, for example:将本地 bin 文件夹添加到路径变量,例如:

 $ export PATH="$MY_INSTALL_DIR/bin:$PATH"

Install cmake You need version 3.13 or later of cmake.安装 cmake 您需要 3.13 或更高版本的 cmake。 Install it by following these instructions:按照以下说明安装它:

Linux: Linux:

 $ sudo apt install -y cmake

macOS:苹果系统:

 $ brew install cmake

For general cmake installation instructions, see Installing CMake.有关一般 cmake 安装说明,请参阅安装 CMake。

Check the version of cmake:查看cmake的版本:

 $ cmake --version cmake version 3.19.6

Under Linux, the version of the system-wide cmake can often be too old.在 Linux 下,系统范围的 cmake 的版本通常可能太旧。 You can install a more recent version into your local installation directory as follows:您可以将更新的版本安装到本地安装目录中,如下所示:

 $ wget -q -O cmake-linux.sh https://github.com/Kitware/CMake/releases/download/v3.19.6/cmake-3.19.6-Linux-x86_64.sh $ sh cmake-linux.sh -- --skip-license --prefix=$MY_INSTALL_DIR $ rm cmake-linux.sh

Install other required tools Install the basic tools required to build gRPC:安装其他所需工具 安装构建 gRPC 所需的基本工具:

Linux: Linux:

 $ sudo apt install -y build-essential autoconf libtool pkg-config

macOS:苹果系统:

 $ brew install autoconf automake libtool pkg-config

Clone the grpc repo Clone the grpc repo and its submodules:克隆 grpc 存储库 克隆 grpc 存储库及其子模块:

 $ git clone --recurse-submodules -b v1.42.0 https://github.com/grpc/grpc

Build and install gRPC and Protocol Buffers While not mandatory, gRPC applications usually leverage Protocol Buffers for service definitions and data serialization, and the example code uses proto3.构建和安装 gRPC 和协议缓冲区虽然不是强制性的,但 gRPC 应用程序通常利用协议缓冲区进行服务定义和数据序列化,示例代码使用 proto3。

The following commands build and locally install gRPC and Protocol Buffers:以下命令构建并在本地安装 gRPC 和协议缓冲区:

 $ cd grpc $ mkdir -p cmake/build $ pushd cmake/build $ cmake -DgRPC_INSTALL=ON \ -DgRPC_BUILD_TESTS=OFF \ -DCMAKE_INSTALL_PREFIX=$MY_INSTALL_DIR \../.. $ make -j $ make install $ popd

Important We strongly encourage you to install gRPC locally — using an appropriately set CMAKE_INSTALL_PREFIX — because there is no easy way to uninstall gRPC after you've installed it globally.重要我们强烈建议您在本地安装 gRPC — 使用适当设置的 CMAKE_INSTALL_PREFIX — 因为在全局安装 gRPC 后没有简单的方法可以卸载它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM