繁体   English   中英

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

[英]bazel c++ create and link with shared library

我将基于cbazel教程的 第2阶段提出问题。

通常,此示例将创建与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",
    ],
)

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

如果您在二进制文件中指定linkstatic -flag,它将以静态或共享库的形式链接所有库。 但是我不知道如何仅将某些库链接为共享库。

cc_library(
    name = "hello-greet",
    srcs = ["hello_greet.cc"],
    hdrs = ["hello_greet.h"],
)

cc_binary(
    name = "hello-world",
    srcs = ["main.cc"],
    deps = [
        ":hello-greet",
    ],
    linkstatic=False,
)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM