登录
首页 >  Golang >  Go问答

使用 cc_library 在 go_library 中获取

来源:stackoverflow

时间:2024-03-04 23:39:29 383浏览 收藏

哈喽!今天心血来潮给大家带来了《使用 cc_library 在 go_library 中获取》,想必大家应该对Golang都不陌生吧,那么阅读本文就都不会很困难,以下内容主要涉及到,若是你正在学习Golang,千万别错过这篇文章~希望能帮助到你!

问题内容

考虑以下 build 文件:

load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

cc_library(
    name = "c",
    srcs = [
        "c.c",
        "c.h",
    ],
    hdrs = [
        "c.h",
    ],
)

go_library(
    name = "gl",
    srcs = [
        "g.go",
    ],
    deps = [
        ":c",
    ],
)

bazel build :c 当然可以,但是 bazel build :gl 会出错:

ERROR: /.../BUILD.bazel:14:11: in deps attribute of go_library rule //cog:gl: '//cog:c' does not have mandatory providers: 'GoLibrary'. Since this rule was created by the macro 'go_library_macro', the error might have been caused by the macro implementation

我正在使用最新版本(v0.24.9)的 go_rules。

我已经阅读了有关提供程序的文档(https://docs.bazel.build/versions/master/skylark/lib/skylark-provider.html),但是afaict,它们仅对规则编写者感兴趣。 p>

将 c/c++ 库与 go 代码链接的批准方式是什么?


解决方案


使用 cc_library 作为依赖项的正确方法是使用 cdeps,而不是 deps。只有在那之后,bazel 才会抱怨缺少 cgo。所以正确的咒语是:

go_library(
    name = "gl",
    srcs = [
        "g.go",
    ],
    cdeps = [
        ":c",
    ],
    cgo = True,
)

今天关于《使用 cc_library 在 go_library 中获取》的内容就介绍到这里了,是不是学起来一目了然!想要了解更多关于的内容请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>