我对Bazel和Gtest非常陌生,并且一直试图在名为"species_test".cpp的cpp文件上运行这些测试。这是我一直遇到的主要错误:
Wills-iMac:species Will$ bazel test species_test --test_output=all
ERROR: Skipping 'species_test': no such target '//species:species_test': target 'species_test' not declared in package 'species' defined by /Users/Will/git/orville-regularwills/species/BUILD.bazel
ERROR: no such target '//species:species_test': target 'species_test' not declared in package 'species' defined by /Users/Will/git/orville-regularwills/species/BUILD.bazel
INFO: Elapsed time: 0.473s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)
FAILED: Build did NOT complete successfully (0 packages loaded)
我有两个BUILD.bazel文件:这个是用于.cpp类实现的:
cc_library(
name="species",
srcs=glob(["*.cpp"]),
hdrs=glob(["*.h"]),
visibility=["//visibility:public"]
)
这一个是用于谷歌测试的文件,它有species_test.cpp:
cc_test(
name="species_test",
srcs=["species_test.cpp"],
copts=["-Iexternal/gtest/include"],
deps=[
"@gtest//::main",
"//species"
]
)
这是我的工作区文件:
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
git_repository(
name = "gtest",
remote = "https://github.com/google/googletest",
branch = "v1.10.x",
)
我不知道这个错误指的是什么,我非常感激任何指向正确方向或清除任何东西的东西。
发布于 2021-01-28 23:24:13
读https://docs.bazel.build/versions/master/build-ref.html。包(目录)应该只包含一个BUILD
文件。文件布局应该是这样的:
├── WORKSPACE
└── species
├── BUILD
├── species.cpp
├── species.hpp
└── species_test.cpp
和BUILD
文件:
cc_library(
name="species",
srcs=["species.cpp"],
hdrs=["species.hpp"],
visibility=["//visibility:public"]
)
cc_test(
name="species_test",
srcs=["species_test.cpp"],
deps=[
"@gtest//:main",
":species"
]
)
通知更改:
我已经删除了you
@gtest//::main
species
库还将编译测试文件,这是不需要的
species.hpp
头,因为没有公共接口的库不能被其他目标
copts
来设置包含路径,因为Bazel将为Bazel @gtest//:main
这样做:在Bazel中使用一个冒号来指示目标H 219H 120
您的cc_test
规则依赖于species
目标。:species
是同一包中目标的标签。或者,您也可以使用完整路径//species:species
,其中第一个species
是包的名称(与根目录中的目录路径相同,这是一个WORKSPACE
目录),而:species
是cc_library
目标的名称。
https://stackoverflow.com/questions/65876390
复制相似问题