编译 grpc 错误 zlib_compress 和 zlib_decompress

Posted

技术标签:

【中文标题】编译 grpc 错误 zlib_compress 和 zlib_decompress【英文标题】:compile grpc erro zlib_compress and zlib_decompress 【发布时间】:2021-08-12 20:57:44 【问题描述】:

当我根据https://grpc.io/docs/languages/cpp/quickstart/编译grpc时,运行命令“make”后,遇到这样的错误信息:

Undefined symbols for architecture x86_64:
  "_deflate", referenced from:
      zlib_compress(grpc_slice_buffer*, grpc_slice_buffer*, int) in libgrpc.a(message_compress.cc.o)
      grpc_stream_compress_gzip(grpc_stream_compression_context*, grpc_slice_buffer*, grpc_slice_buffer*, unsigned long*, unsigned long, grpc_stream_compression_flush) in libgrpc.a(stream_compression_gzip.cc.o)
      grpc_stream_compression_context_create_gzip(grpc_stream_compression_method) in libgrpc.a(stream_compression_gzip.cc.o)
  "_deflateEnd", referenced from:
      zlib_compress(grpc_slice_buffer*, grpc_slice_buffer*, int) in libgrpc.a(message_compress.cc.o)
      grpc_stream_compression_context_destroy_gzip(grpc_stream_compression_context*) in libgrpc.a(stream_compression_gzip.cc.o)
  "_deflateInit2_", referenced from:
      zlib_compress(grpc_slice_buffer*, grpc_slice_buffer*, int) in libgrpc.a(message_compress.cc.o)
      grpc_stream_compression_context_create_gzip(grpc_stream_compression_method) in libgrpc.a(stream_compression_gzip.cc.o)
  "_inflate", referenced from:
      zlib_decompress(grpc_slice_buffer*, grpc_slice_buffer*, int) in libgrpc.a(message_compress.cc.o)
      grpc_stream_decompress_gzip(grpc_stream_compression_context*, grpc_slice_buffer*, grpc_slice_buffer*, unsigned long*, unsigned long, bool*) in libgrpc.a(stream_compression_gzip.cc.o)
      grpc_stream_compression_context_create_gzip(grpc_stream_compression_method) in libgrpc.a(stream_compression_gzip.cc.o)
      grpc_stream_compression_context_destroy_gzip(grpc_stream_compression_context*) in libgrpc.a(stream_compression_gzip.cc.o)
      gzip_flate(grpc_stream_compression_context_gzip*, grpc_slice_buffer*, grpc_slice_buffer*, unsigned long*, unsigned long, int, bool*) in libgrpc.a(stream_compression_gzip.cc.o)
  "_inflateEnd", referenced from:
      zlib_decompress(grpc_slice_buffer*, grpc_slice_buffer*, int) in libgrpc.a(message_compress.cc.o)
      grpc_stream_compression_context_destroy_gzip(grpc_stream_compression_context*) in libgrpc.a(stream_compression_gzip.cc.o)
  "_inflateInit2_", referenced from:
      zlib_decompress(grpc_slice_buffer*, grpc_slice_buffer*, int) in libgrpc.a(message_compress.cc.o)
      grpc_stream_compression_context_create_gzip(grpc_stream_compression_method) in libgrpc.a(stream_compression_gzip.cc.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libgrpc_csharp_ext.15.0.0.dylib] Error 1
make[1]: *** [CMakeFiles/grpc_csharp_ext.dir/all] Error 2
make: *** [all] Error 2

【问题讨论】:

【参考方案1】:

我错过了 git clone 三十方/zlib 的任务失败,我很抱歉。 在构建 grpc 时,我遇到错误消息:

    gRPC_ABSL_PROVIDER 是“模块”但 ABSL_ROOT_DIR 错误 解决方法:参考https://github.com/spack/spack/issues/15619和https://github.com/spack/spack/pull/16052 在 grpc 文件夹下,运行以下命令
        git submodule update --init

然后

cd ./cmake/build

并运行以下命令

    cmake -DgRPC_INSTALL=ON \
          -DgRPC_BUILD_TESTS=OFF \
          -DCMAKE_INSTALL_PREFIX=$MY_INSTALL_DIR \
          ../..
    三十方zlib git clone 失败导致cmake失败,只需进入三十方文件夹即可
cd thirty-party/

git clone https://github.com/madler/zlib
    third_party/abseil-cpp 编译失败,因为它的 CMakeList.txt 需要添加一行,即
set(CMAKE_CXX_FLAGS "-std=c++11")

在开始但在 cmake_minimum_required(***) 之后。 参考https://www.jianshu.com/p/08fdf54fbf43

    安装abseil-cpp时遇到问题: cmake_install.cmake:53(文件)处的 CMake 错误: 文件无法创建目录:/lib/cmake/absl。也许需要管理权限。 这是因为我取消了 MY_INSTALL_DIR。也许你改变了窗口,在那个窗口,你不导出 MY_INSTALL_DIR

【讨论】:

以上是关于编译 grpc 错误 zlib_compress 和 zlib_decompress的主要内容,如果未能解决你的问题,请参考以下文章

gRPC 给定 PHP 的错误元数据

GRPC使用错误排查记录

Xcode gRPC-Core 错误:找不到“openssl_grpc/ssl.h”文件

编译gRPC

将 grpc 与 QtCreator 一起使用,未定义对 `grpc::...` 的引用

CMake方式编译grpc