gRPC 不为 ubuntu 上的 c++ 生成库
gRPC doesn't produce libraries for c++ on ubuntu
当我试图在文件夹gRPC/examples/cpp/helloworld中运行gRPC for c++的示例时,它需要使用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
我犯了几个错误,通过将grpcpppplugin从文件夹grpc/bins/opt复制到/usr/local/bin,并将grpc++.pc和grpc++_unsecure.pc从grpc/libs/opt/pkgconfig/复制到/usr/local/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文件夹中搜索了这些libs-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$||'`;
只有两条线
看起来您只从third_party/protobuf
目录运行了make
(第一步需要这样做),并从helloworld
目录运行了make
。如果您还没有这样做,您应该根据文档从grpc存储库root目录运行make
。这将确保libgrpc++*
C++库的构建。
所以,我解决了这个问题。当我在根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
因为所有警告都被视为错误。另一个库的编译也停止了。因此,我在根目录gRPC的Makefile中手动添加了357行末尾的标志-Wno-unused-variable
。添加此标志后,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
- Linux的Cpp上的计时器
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- 物理键盘上的触发器按键
- 如何加载(或映射)文件部分的最大大小,但适合在Windows上的RAM
- SSL上的`curl_easy_send`和`curl_asy_recv`:如何处理`CURLE_AGAIN`
- PowerPC ppc64le上的Gcc Woverloaded虚拟错误
- 为什么在Windows上的VS 2019和Clang 9中"size_t"在没有标题的情况下工作
- 集合上的输出迭代器:assign和increment迭代器
- Cuda C++:设备上的Malloc类,并用来自主机的数据填充它
- 为什么我在leetcode上收到AddressSanitizer:地址0x602000000058上的堆缓冲区溢出错误
- 对于set上的循环-获取next元素迭代器
- 如何从棋盘上的箱号中找到行和列
- 为什么除非添加括号,否则构造函数上的模板替换会失败?
- if数组上的随机数
- 向量上的线性搜索
- 位阵列上的快速AND运算
- 无法将 GLFW 库与 Ubuntu 18.04 上的头文件链接
- 为什么一个向量上的多线程操作很慢
- 64位机器上的C++内存对齐
- 跟踪滚动条上的鼠标事件