簡體   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