gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 03:19:39 49 4
gpt4 key购买 nike

我的问题将基于 bazel tutorial for c++阶段 2 .

通常此示例将创建 hello-worldlibhello-greet.a 链接静态。但是,我想创建 hello-worldlibhello-greet.so 链接动态

因此,我通过使用此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,
)

关于c++ - bazel c++ 创建并链接共享库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53514630/

49 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com