bazel linkshared option creates a large shared library

Viewed 29

I'm using bazel to build a shared libary, but the output so file size is much bigger than expected; For comparision I also build a binary with same deps and srcs in BUILD file, the binary ouput size is much smaller; Code sample:

cc_binary(
   name = "server",
   srcs = ["server.cc"],
   deps = [...]
)  # the binary

cc_binary(
   name = "libs.so",
   srcs = ["server.cc"],
   deps = [...],
   linkshared = 1
)   # the shared library

libs.so is about 5 times larger than server; It seems linkshared option packs all symbols in deps to the shared library, including unused functions, variables(nm shows libs.so contains much more symbols than server); How can I just link needed symbols to my shared library?

1 Answers

Well, if you're compiling a shared library, there is no such thing as "unused functions". You're creating a library with functions that an executable can use.

Related