bazel c++ 创建并链接共享库

Chr*_*aes 5 c++ shared-libraries bazel

我的问题将基于bazel c++ 教程的第二阶段。

通常,此示例将创建与libhello-greet.a静态链接的hello-world。不过,我想创建与libhello-greet.so动态链接的hello-world。

因此,我通过使用此BUILD文件找到了某种解决方法:

cc_binary(
    name = "libhello-greet.so",
    srcs = ["hello-greet.cc", "hello-greet.h"],
    linkshared = 1,
)

cc_import(
    name = "libhello-greet",
    shared_library = "libhello-greet.so",
    hdrs = ["hello-greet.h"],
)   

cc_binary(
    name = "hello-world",
    srcs = ["hello-world.cc"],
    deps = [
        ":libhello-greet",
    ],
)
Run Code Online (Sandbox Code Playgroud)

但这感觉不是最好的解决方案。有没有更好的方法来创建和链接共享库?