使用 cc_library 在 go_library 中获取
时间:2024-03-04
浏览: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学习网公众号!
本文内容来源于互联网,如有侵权请联系删除。
近期热门
11.18
11.15
站内热门
最新文章
12.01
12.01
热门专题
