9

I would like to create a shared c++ library with Bazel using a soname.

With cmake I could set properties like:

set_target_properties(my-library
        PROPERTIES
                SOVERSION 3
                VERSION 3.2.0
        )

which would then generate

libmy-library.so -> libmy-library.so.3
libmy-library.so.3 -> libmy-library.so.3.2.0
libmy-library.so.3.2.0

However in bazel documentation I cannot find anything that would allow me to do so easily. I know that I could define the soname and version directly and pass some linkopts in the build file:

cc_binary(
    name = "libmy-library.so.3.2.0",
    srcs = ["my-library.cpp", "my-library.h"],
    linkshared = 1,
    linkopts = ["-Wl,-soname,libmy-library.so.3"],
)

which does produce libmy-library.so.3.2.0 with the correct soname, but not the .so file so it would require a whole lot of hacks around to:

  • create libmy-library.so.3 symlink
  • create libmy-library.so symlink
  • create some import rules such that I can build binaries that link with this library.

This does not feel like the right way. What would be the right way to solve such problem?

Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
Chris Maes
  • 35,025
  • 12
  • 111
  • 136
  • I know it's been a while since this was asked. But what is the end result that you are trying to achieve? e.g. Are you attempting to make a deb/rpm/tar? – silvergasp Jun 29 '22 at 20:55

0 Answers0