我正在尝试在docker上部署C ++ GRPC服务器。不幸的是,grpc示例使用动态链接的GRPC库。将可执行文件复制到docker(例如,基于阿尔卑斯山的小型文件)时,它会响应“未找到”。潜在的问题是可执行文件依赖于动态链接的GRPC库。
我将GRPC的示例Makefile更新为[仅更改是添加-static]
HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
SYSTEM ?= $(HOST_SYSTEM)
CXX = g++
CPPFLAGS += `pkg-config --cflags protobuf grpc`
CXXFLAGS += -std=c++11
ifeq ($(SYSTEM),Darwin)
LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc`\
-lgrpc++_reflection\
-ldl
else
LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc`\
-Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed\
-ldl
endif
PROTOC = protoc
GRPC_CPP_PLUGIN = grpc_cpp_plugin
GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)`
PROTOS_PATH = ../../protos
vpath %.proto $(PROTOS_PATH)
all: system-check greeter_client greeter_server greeter_async_client greeter_async_client2 greeter_async_server
greeter_client: helloworld.pb.o helloworld.grpc.pb.o greeter_client.o
$(CXX) $^ $(LDFLAGS) -o $@ -static
但是,这会遇到
Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/local/lib/libgrpc.a(message_compress.o):(.text+0x43d): undefined reference to `deflateInit2_'
/usr/local/lib/libgrpc.a(message_compress.o):(.text+0x44e): undefined reference to `deflate'
/usr/local/lib/libgrpc.a(message_compress.o):(.text+0x4bb): undefined reference to `deflateEnd'
/usr/local/lib/libgrpc.a(message_compress.o):(.text+0x5bc): undefined reference to `inflateInit2_'
/usr/local/lib/libgrpc.a(message_compress.o):(.text+0x5cb): undefined reference to `inflate'
/usr/local/lib/libgrpc.a(message_compress.o):(.text+0x63b): undefined reference to `inflateEnd'
如何调整它以使静态编译的GRPC客户端/服务器正常工作?
答案 0 :(得分:0)
您缺少使用-lz
来修复此错误的链接压缩库。