├── app
│ ├── BUILD
│ ├── hello_world.cpp
│ └── lib
│ ├── BUILD
│ ├── func.cpp
│ └── func.hpp
├── README.md
└── WORKSPACEbash
咱们知道子目录下再建立一个BUILD文件,那么该子目录也是一个Package。app
app/BUILD:函数
cc_binary( name = "hello_world", srcs = ["hello_world.cpp"], deps = ["//app/lib:hello_func",], )
hello_world目标须要调用func1()函数,因此须要依赖lib包。code
lib/BUILD:it
cc_library( name = "hello_func", srcs = ["func.cpp"], hdrs = ["func.hpp"], visibility = ["//app:__pkg__"], )
The
visibility
attribute on a rule controls whether the rule can be used by other packages. Rules are always visible to other rules declared in the same package.class
visibility属性至关于设置规则的可见域,使其余规则可以使用本规则。这里的“//app:__pkg__”代表app包能够访问本规则。sed