bazel-编译静态库

demo3 使用bazel编译静态库

demo3目录树

├── README.md
├── static
│ ├── BUILD
│ ├── static.c
│ └── static.h
└── WORKSPACE

BUILD

cc_library(
    name = "static",
    srcs = ["static.c","static.h"],
    linkstatic = True,
)

本例中,包名即目录名static,cc_library规则的name也为static即目标名,所以在当前根目录下执行bazel build //static:static

bazel自动加上lib 和 .a,最终生成liibstatic.a

https://github.com/suonikeyinsuxiao/trunk/blob/master/bazel_zoo/project/demo3/Selection_071.png

https://github.com/suonikeyinsuxiao/trunk/blob/master/bazel_zoo/project/demo3/Selection_070.png

再简单的验证一下静态库是否有效

vi main.c

调用print_static函数

gcc test.c libstatic.a -o a.out 编译得到a.out(会有编译警告,因为没有包含头文件)

执行a.out,即可看到打印"I'm static"

posted @ 2018-10-23 09:04  suonikeyinsu  Views(3763)  Comments(0Edit  收藏  举报