$ man pkg-config

--static
              Output  libraries suitable for static linking.  That means including any private libraries in the output.  This relies on proper tag‐
              ging in the .pc files, else a too large number of libraries will ordinarily be output.
 

以examples/cpp/route_guide 为例:

修改make file:

1、给 pkg-config 添加 --static 选项:

LDFLAGS += -L/usr/local/lib `pkg-config --libs --static protobuf grpc++`\
           -pthread\
           -Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed\
           -ldl

2、CPPFLAGS, CXXFLAGS ,LDFLAGS 分别加上 -static

更多推荐