title: Compiling GRPC C++ service statically
body: <p>I am trying to deploy a C++ GRPC server on docker. Unfortunately, the grpc examples use dynamically linked GRPC libraries. When copying the executables to docker (e.g. a small alpine based one) it responds "not found". The underlying problem is that the executable depends on dynamically linked GRPC libraries.</p>
  
  <p>I updated the example Makefile of GRPC to [only change is adding -static]</p>
  
  <pre><code>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
  </code></pre>
  
  <p>However, this runs into </p>
  
  <pre><code>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'
  </code></pre>
  
  <p>How can I adjust this to get a working statically compiled GRPC client / server?</p>