【问题标题】:gRPC doesn't produce libraries for c++ on ubuntugRPC 不会在 ubuntu 上为 c++ 生成库
【发布时间】:2019-12-25 22:34:59
【问题描述】:

当我尝试在文件夹 grpc/examples/cpp/helloworld 中运行用于 c++ 的 gRPC 示例时,它需要在我使用 Cmake 构建 gRPC 时未编译的库

首先我在 Ububtu 16.04 中使用说明构建了 gRPC:

$ git clone -b $(curl -L https://grpc.io/release) https://github.com/grpc/grpc
$ cd grpc
$ git submodule update --init
$ cd third_party/protobuf
$ git submodule update --init --recursive
$ ./autogen.sh
$ ./configure --prefix=/usr
$ make
$ make check
$ sudo make install
$ sudo ldconfig # refresh shared library cache.
$ pkg-config --cflags protobuf         # print compiler flags
$ pkg-config --libs protobuf           # print linker flags
$ pkg-config --cflags --libs protobuf  # print both
cd ../..
make
sudo make install 

之后我尝试在文件夹 grpc/examples/cpp/helloworld 中运行示例

grps/grpc/examples/cpp/helloworld$ make

我遇到了几个错误,通过将 grpc_cpp_plugin 从文件夹 grpc/bins/opt 复制到 /usr/local/bin 和 grpc++.pc 和 grpc++_unsecure.pc 从 grpc/libs/opt/pkgconfig/ 复制到 / usr/本地/lib/pkgconfig。 当我尝试下一次命令时

grpc/examples/cpp/helloworld$ make

我有消息

g++ helloworld.pb.o helloworld.grpc.pb.o greeter_client.o -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc` -pthread -Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed -ldl -o greeter_client
/usr/bin/ld: cannot find -lgrpc++
/usr/bin/ld: cannot find -lgrpc++_reflection
collect2: error: ld returned 1 exit status
Makefile:44: recipe for target 'greeter_client' failed
make: *** [greeter_client] Error 1

所以,我在文件夹 grpc/libs/opt 中搜索了这些库 libgrpc++,但只有这些库

grpc/libs/opt$ ls --l 
libaddress_sorting.a         libgrpc_cronet.so.8
libaddress_sorting.so        libgrpc_cronet.so.8.0.0
libaddress_sorting.so.8      libgrpc_plugin_support.a
libaddress_sorting.so.8.0.0  libgrpc.so
libares.a                    libgrpc.so.8
libboringssl.a               libgrpc.so.8.0.0
libgpr.a                     libgrpc_unsecure.a
libgpr.so                    libgrpc_unsecure.so
libgpr.so.8                  libgrpc_unsecure.so.8
libgpr.so.8.0.0              libgrpc_unsecure.so.8.0.0
libgrpc.a                    pkgconfig
libgrpc_cronet.a             protobuf
libgrpc_cronet.so

所以 make 没有为 gRPC 编译静态和动态库。是我做错了什么还是什么都没做或有错误? protobuf 的版本是

:~$ protoc --version
libprotoc 3.8.0
:~$ which protoc
/usr/bin/protoc

这是我从根目录运行“make”后的一些输出

[MAKE]    Generating /home/user/cpp_test/grps/grpc/libs/opt/pkgconfig/grpc++.pc
[MAKE]    Generating /home/user/cpp_test/grps/grpc/libs/opt/pkgconfig/grpc++_unsecure.pc

因此它会为“libgrpc++*”库创建 pkgconfig 文件,但不会创建这些库。
而这些有 libgrpc++

 libgrpc++ depbase=`echo google/protobuf/io/tokenizer.lo | sed 's|[^/]*$|.deps/&|;s|\.lo$||'`;\

libgrpc++ depbase=`echo google/protobuf/util/delimited_message_util.lo | sed 's|[^/]*$|.deps/&|;s|\.lo$||'`;\

只有两行

【问题讨论】:

  • "但只有 C 库" - 你怎么知道那些是 C 库?其次,为什么它们是 C 库会成为问题? C++ 代码可以使用大多数(几乎所有)C 库。
  • 我的意思是在 grpc/libs/opt 中必须至少有 libgrpc++.a、libgrpc++.so、libgrpc++_unsecure.a 和 libgrpc++_unsecure.so 的库。但我没有在这个文件夹中。
  • 是的,应该有一个 libgrpc++.so 和一个 libgrpc++_reflection.so 被构建。

标签: c++ ubuntu cmake grpc


【解决方案1】:

所以,我解决了这个问题。 当我在根 gRPC 文件夹上运行“make”时,编译以这样的结果结束:

[CXX]     Compiling /home/user/cpp_test/grps/grpc/gens/src/proto/grpc/core/stats.pb.cc
/home/user/cpp_test/grps/grpc/gens/src/proto/grpc/core/stats.pb.cc:187:13: error: ‘dynamic_init_dummy_src_2fproto_2fgrpc_2fcore_2fstats_2eproto’ defined but not used [-Werror=unused-variable]
 static bool dynamic_init_dummy_src_2fproto_2fgrpc_2fcore_2fstats_2eproto = []()
             ^
cc1plus: all warnings being treated as errors
Makefile:2924: recipe for target '/home/user/cpp_test/grps/grpc/objs/opt//home/user/cpp_test/august/grpc/gens/src/proto/grpc/core/stats.pb.o' failed
make: *** [/home/user/cpp_test/grps/grpc/objs/opt//home/user/cpp_test/august/grpc/gens/src/proto/grpc/core/stats.pb.o] Error 1 

因为所有警告都被视为错误。并且停止编译另一个库。所以我在 Makefile 的根 gRPC 目录标志 -Wno-unused-variable 在 357 行的末尾手动添加。添加此标志后gRPC库构建成功,所有libgrpc++*和libgrpc*库都构建完成。

CPPFLAGS += -g -Wall -Wextra -Werror $(W_NO_UNKNOWN_WARNING_OPTION) -Wno-long-long -Wno-unused-parameter -Wno-deprecated-declarations -Wno-sign-conversion -Wno-shadow -Wno-conversion -Wno-implicit-fallthrough -Wno-sign-compare -Wno-missing-field-initializers -Wno-maybe-uninitialized -DPB_FIELD_32BIT -DOSATOMIC_USE_INLINED=1 -Ithird_party/nanopb -Ithird_party/upb -Isrc/core/ext/upb-generated -Wno-unused-variable

【讨论】:

    【解决方案2】:

    您似乎只从third_party/protobuf 目录运行make(第一步需要这样做),并从helloworld 目录运行make。如果您还没有这样做,您应该按照documentation 从grpc 存储库root 目录运行make。这将确保构建libgrpc++* C++ 库。

    【讨论】:

    • 不,我编辑了我的代码。我只是忘记编写整个命令来构建 gRPC。
    猜你喜欢
    • 2016-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-03
    • 2021-06-09
    • 1970-01-01
    • 2016-09-19
    相关资源
    最近更新 更多